docker-compose使用host网络
docker-compose使用host网络
根据官方文档, 如果使用stack命令部署,可以使用networks参数配置,如果直接使用docker-compose, 使用network_mode参数配置。
Use the host’s networking stack, or no networking. Equivalent to docker run –net=host or docker run –net=none. Only used if you use docker stack commands. If you use the docker-compose command, use network_mode instead. —-compose file reference: https://docs.docker.com/compose/compose-file/#devices
stack
version: "3.8"
services:
web:
networks:
hostnet: {}
networks:
hostnet:
external: true
name: host
docker-compose
services:
web:
network_mode: "host"
问题
如果在docker-compose中使用networks参数配置系统默认网卡,会报以下错误:
Creating zerotier-one ... error
ERROR: for zerotier-one network-scoped alias is supported only for containers in user defined networks
ERROR: for one network-scoped alias is supported only for containers in user defined networks
ERROR: Encountered errors while bringing up the project.