前情提要
我在用docker-compose启动容器的时候,yml文件里配置了四个容器,另一个yml文件也配置了四个容器
问题
docker-compose up启动容器的时候,一个启动成功了,启动另一个,总是会把之前的yml文件启动的四个容器停掉
下面是我的两个yml文件,容器名是不一样
# 1
version: '3.7'
services:
nginx_server:
image: "ubuntu:ultimate"
volumes:
- "/app:/app"
restart: always
container_name: nginx1
privileged: true
entrypoint: [ "/app/download.sh" ]
networks:
- net1
test1:
image: "ubuntu:ultimate"
volumes:
- "/app:/app"
restart: always
container_name: test1
privileged: true
depends_on:
- nginx_server
networks:
- net1
entrypoint: [ "/app/pin.sh" ]
test2:
image: "ubuntu:ultimate"
volumes:
- "/app:/app"
restart: always
container_name: test2
privileged: true
depends_on:
- nginx_server
networks:
- net1
entrypoint: [ "/app/pin1.sh" ]
test3:
image: "ubuntu:ultimate"
volumes:
- "/app:/app"
restart: always
container_name: test3
privileged: true
depends_on:
- nginx_server
networks:
- net1
entrypoint: [ "/app/pin2.sh" ]
networks:
net1:
external: true
name: net111111
# 2
version: '3.7'
services:
nginx_server:
image: "ubuntu:ultimate"
volumes:
- "/app:/app"
restart: always
container_name: nginx2
privileged: true
entrypoint: [ "/app/download.sh" ]
networks:
- net1
test1:
image: "ubuntu:ultimate"
volumes:
- "/app:/app"
restart: always
container_name: test11
privileged: true
depends_on:
- nginx_server
networks:
- net1
entrypoint: [ "/app/pin.sh" ]
test2:
image: "ubuntu:ultimate"
volumes:
- "/app:/app"
restart: always
container_name: test22
privileged: true
depends_on:
- nginx_server
networks:
- net1
entrypoint: [ "/app/pin1.sh" ]
test3:
image: "ubuntu:ultimate"
volumes:
- "/app:/app"
restart: always
container_name: test33
privileged: true
depends_on:
- nginx_server
networks:
- net1
entrypoint: [ "/app/pin2.sh" ]
networks:
net1:
name: net222222
driver: bridge
ipam:
driver: default
config:
- subnet: 172.16.200.0/24
gateway: 172.16.200.1
解决
问题出在红色框框部分,yml配置文件中这些名字也是不可以重复的,即使是不同的yml文件中,名称也不能相同。
改一下就行了
# 3
version: '3.7'
services:
nginx_server1:
image: "dpdk:v1.0.3"
volumes:
- "/app:/app"
restart: always
container_name: nginx1
privileged: true
entrypoint: [ "/app/download.sh" ]
networks:
- net11
test11:
image: "dpdk:v1.0.3"
volumes:
- "/app:/app"
restart: always
container_name: test1
privileged: true
depends_on:
- nginx_server
networks:
- net11
entrypoint: [ "/app/pin.sh" ]
test12:
image: "dpdk:v1.0.3"
volumes:
- "/app:/app"
restart: always
container_name: test2
privileged: true
depends_on:
- nginx_server
networks:
- net11
entrypoint: [ "/app/pin1.sh" ]
test13:
image: "dpdk:v1.0.3"
volumes:
- "/app:/app"
restart: always
container_name: test3
privileged: true
depends_on:
- nginx_server
networks:
- net11
entrypoint: [ "/app/pin2.sh" ]
networks:
net11:
external: true
name: net111111
启起来了!