如何使 Network_Mode : "host" 在 docker-compose.yml 文件中工作
How to make Network_Mode : "host" work in docker-compose.yml file
我正在尝试执行“docker-compose up”命令。请在下面找到我的 docker-compose 文件。我试过 network_mode: "host" 但它不起作用。我在 Linux OS。如果我犯了任何错误,请您告诉我。
version: '3.6'
services:
mongo:
image: "mongo:latest"
container_name: ohif-mongo
ports:
- "27017:27017"
viewer:
image: ohif/viewer:latest
container_name: ohif-viewer
ports:
- "3030:80"
network_mode: "host" # please make note of the alignment
links:
- mongo
environment:
- MONGO_URL=mongodb://mongo:27017/ohif
extra_hosts:
- "pacsIP:172.xx.xxx.xxx"
volumes:
- ./dockersupport-app.json:/app/app.json
执行后,出现以下错误
ERROR: for 8f4c3de7e3a3_ohif-viewer Cannot create container for service viewer: conflicting options: host type networking can't be used with links. This would result in undefined behavior
ERROR: for viewer Cannot create container for service viewer: conflicting options: host type networking can't be used with links. This would result in undefined behavior
我不知道为什么错误信息会显示两次。不确定这是否符合预期
其次,当我更改 network_mode 的对齐方式时:"host"(1/2 个空格)
ports:
- "3030:80"
network_mode: "host" # please see the change in alignment now
links:
- mongo
我收到以下错误消息
ERROR: yaml.parser.ParserError: while parsing a block mapping
in "./docker-compose.yml", line 10, column 5
expected <block end>, but found '<block mapping start>'
in "./docker-compose.yml", line 14, column 6
如何以network=host模式启动容器?
来自docs:
network_mode: "host" cannot be mixed with links.
Warning: The --link flag is a legacy feature of Docker. It may eventually be removed. Unless you absolutely need to continue using it, we recommend that you use user-defined networks to facilitate communication between two containers instead of using --link. One feature that user-defined networks do not support that you can do with --link is sharing environmental variables between containers. However, you can use other mechanisms such as volumes to share environment variables between containers in a more controlled way.
只需删除链接。不再需要它们。
network_mode: host
用于与主机共享同一网络space。例如,您可能想要从容器访问 Linux PC 上 运行 的应用程序。
如果你想 link 服务在一起,你可以使用 links
或 depends_on
,如果服务在不同的主机上,只需创建一个覆盖网络
我正在尝试执行“docker-compose up”命令。请在下面找到我的 docker-compose 文件。我试过 network_mode: "host" 但它不起作用。我在 Linux OS。如果我犯了任何错误,请您告诉我。
version: '3.6'
services:
mongo:
image: "mongo:latest"
container_name: ohif-mongo
ports:
- "27017:27017"
viewer:
image: ohif/viewer:latest
container_name: ohif-viewer
ports:
- "3030:80"
network_mode: "host" # please make note of the alignment
links:
- mongo
environment:
- MONGO_URL=mongodb://mongo:27017/ohif
extra_hosts:
- "pacsIP:172.xx.xxx.xxx"
volumes:
- ./dockersupport-app.json:/app/app.json
执行后,出现以下错误
ERROR: for 8f4c3de7e3a3_ohif-viewer Cannot create container for service viewer: conflicting options: host type networking can't be used with links. This would result in undefined behavior
ERROR: for viewer Cannot create container for service viewer: conflicting options: host type networking can't be used with links. This would result in undefined behavior
我不知道为什么错误信息会显示两次。不确定这是否符合预期
其次,当我更改 network_mode 的对齐方式时:"host"(1/2 个空格)
ports:
- "3030:80"
network_mode: "host" # please see the change in alignment now
links:
- mongo
我收到以下错误消息
ERROR: yaml.parser.ParserError: while parsing a block mapping
in "./docker-compose.yml", line 10, column 5
expected <block end>, but found '<block mapping start>'
in "./docker-compose.yml", line 14, column 6
如何以network=host模式启动容器?
来自docs:
network_mode: "host" cannot be mixed with links.
Warning: The --link flag is a legacy feature of Docker. It may eventually be removed. Unless you absolutely need to continue using it, we recommend that you use user-defined networks to facilitate communication between two containers instead of using --link. One feature that user-defined networks do not support that you can do with --link is sharing environmental variables between containers. However, you can use other mechanisms such as volumes to share environment variables between containers in a more controlled way.
只需删除链接。不再需要它们。
network_mode: host
用于与主机共享同一网络space。例如,您可能想要从容器访问 Linux PC 上 运行 的应用程序。
如果你想 link 服务在一起,你可以使用 links
或 depends_on
,如果服务在不同的主机上,只需创建一个覆盖网络