使不同的dockerCompose文件启动的容器能互相访问
有两个文件,处于不同的文件夹下
docker-compose-1.yml
version: "3"
services:
docker-1:
image: xxx
container_name: container1
hostname: host1
docker-compose-2.yml
version: "3"
services:
docker-2:
image: xxx
container_name: container2
hostname: host2
需要让两个容器能够访问,则需要加个网络
docker-compose-1.yml
version: "3"
services:
docker-1:
image: xxx
container_name: container1
hostname: host1
networks:
- testnet
networks:
testnet:
name: my_testnet
driver: bridge
docker-compose-2.yml
version: "3"
services:
docker-2:
image: xxx
container_name: container2
hostname: host2
networks:
- my_testnet
networks:
my_testnet:
external: true
这两两个docker就可以通过容器名互相访问了,前提是第一个文件需要先启动