简体   繁体   English

Docker-Compose:可以在不同的容器上强制使用IP地址吗?

[英]Docker-Compose: is it possible to force IP addresses on different containers?

I was reading through these docs, https://docs.docker.com/compose/networking/ 我正在阅读这些文档, https://docs.docker.com/compose/networking/

version: '2'

services:
  web:
    build: .
    ports:
      - "8000:8000"

Through this, I know that I could access the IP Address where web is located via something like myapp_web , depending on how I configure it, but is it possible to do something like: 通过这个,我知道我可以通过类似myapp_web访问web所在的IP地址,具体取决于我如何配置它,但是可以这样做:

version: '2'

services:
  web:
    build: .
    ip: 172.0.0.4
    ports:
      - "8000:8000"

Which would force web to be located at the IP address 172.0.0.4? 哪个会强制web位于IP地址172.0.0.4? I haven't found anything in the docs about this. 我没有在文档中找到任何关于此的内容。

If you want static ip address you need create user-defined network. 如果您需要静态IP地址,则需要创建用户定义的网络。 And use any address you want. 并使用您想要的任何地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM