使用Docker设置多个Ubuntu容器

需求:

基于Ubuntu 14.04的docker实例的设置,其中1个实例的行为像一个网关,用于所有其他networking通信。

为这样的设置创build一个泊坞窗撰写文件…

所有这些情况都需要在他们自己的专用dockernetworking和默认docker桥接器上进行。

创build了一个Dockerfile

FROM ubuntu:14.04 # Set environment variables. ENV HOME /root # Define working directory. WORKDIR /root # Define default command. CMD ["/bin/bash"] 

泊坞窗,compose.yml

 version: '3' services: main: image: testenginer_main tty: true first: image: testenginer_main tty: true 

其中testenginer_main是我使用Dockerfile设置生成的图像文件
我检查了这两个实例正在运行

问题是我想有2个networking1连接到docker的默认桥接networking和第二个连接到其他容器,使其他容器可以通过networking1访问主networking

编辑-1

如果您需要在主networking上访问Internet,则需要前两个networking

 docker network create --subnet=172.19.0.0/16 internet docker network create --internal --subnet 10.1.1.0/24 no-internet 

对于上面你可以看看更多的细节

限制互联网访问 – Docker容器

现在您可以更新撰写如下

 version: '3' services: main: image: testenginer_main tty: true networks: - internet - no-internet first: image: testenginer_main tty: true networks: - no-internet networks: no-internet: external: true internet: external: true 

现在,如果你运行的容器,你会看到main有互联网访问,而first没有

 $ docker-compose ps Name Command State Ports -------------------------------------- ub_first_1 /bin/bash Up ub_main_1 /bin/bash Up $ docker-compose exec main apt update Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB] ^C $ docker-compose exec first apt update Err:1 http://archive.ubuntu.com/ubuntu xenial InRelease Temporary failure resolving 'archive.ubuntu.com' Err:2 http://security.ubuntu.com/ubuntu xenial-security InRelease Temporary failure resolving 'security.ubuntu.com' .... W: Some index files failed to download. They have been ignored, or old ones used instead. 

你甚至可以使每个组合创build自己的networking与选项