我在这里面临一个问题:
version: '2'
services:
ms1:
image: somedtr/someorg/somerepo:v0.1
mem_limit: 512M
environment:
SPRING_PROFILES_ACTIVE: docker-development-cloud
JAVA_OPTS: -Xms256m -Xmx512m
ports:
- "8900:8900"
restart: always
networks:
- docker_dev_cloud
networks:
docker_dev_cloud:
driver: bridge
=======================================
version: '2'
services:
ms2:
image: somedtr/someorg/somerepo:v0.1
mem_limit: 512M
environment:
SPRING_PROFILES_ACTIVE: docker-development-cloud
JAVA_OPTS: -Xms256m -Xmx512m
ports:
- "8900:8900"
restart: always
networks:
- docker_dev_cloud
networks:
docker_dev_cloud:
driver: bridge
我正在尝试在docker_dev_cloud上运行该服务,但它没有在该网络上运行
当我做docker network ls时
ms1_docker_dev_cloud
ms2_docker_dev_cloud
任何赞赏的帮助, 在此先感谢
答案 0 :(得分:0)
OP使用了2个不同的.yaml
文件,并且正在创建2个不同的网络,可能是因为docker-compose
将项目名称(默认情况下)用作docker-compose.yaml
文件的目录名称。在评论中建议使用:
docker-compose -p project_name up
我已经改变了你的yaml
,以便制作出有效且可以展示的东西。
alpine
图片entrypoint: ping msX
以告诉您他们互相ping。 docker-compose.yaml(用docker-compose up
运行):
version: '2'
services:
ms1:
image: alpine
mem_limit: 512M
environment:
SPRING_PROFILES_ACTIVE: docker-development-cloud
JAVA_OPTS: -Xms256m -Xmx512m
ports:
- "8900:8900"
restart: always
networks:
- docker_dev_cloud
entrypoint: ping ms2
ms2:
image: alpine
mem_limit: 512M
environment:
SPRING_PROFILES_ACTIVE: docker-development-cloud
JAVA_OPTS: -Xms256m -Xmx512m
ports:
- "8901:8900"
restart: always
networks:
- docker_dev_cloud
entrypoint: ping ms1
networks:
docker_dev_cloud:
driver: bridge
你可以看到它有效,因为ms1 - ms2实际上互相ping。
ubuntu@ubuntu:~/docker_compose_tests/test$ docker-compose up
Creating network "test_docker_dev_cloud" with driver "bridge"
Creating test_ms1_1
Creating test_ms2_1
Attaching to test_ms2_1, test_ms1_1
ms2_1 | PING ms1 (172.22.0.3): 56 data bytes
ms2_1 | 64 bytes from 172.22.0.3: seq=0 ttl=64 time=0.070 ms
ms1_1 | PING ms2 (172.22.0.2): 56 data bytes
ms1_1 | 64 bytes from 172.22.0.2: seq=0 ttl=64 time=0.054 ms
ms2_1 | 64 bytes from 172.22.0.3: seq=1 ttl=64 time=0.286 ms
ms1_1 | 64 bytes from 172.22.0.2: seq=1 ttl=64 time=0.113 ms
ms2_1 | 64 bytes from 172.22.0.3: seq=2 ttl=64 time=0.129 ms
ms1_1 | 64 bytes from 172.22.0.2: seq=2 ttl=64 time=0.086 ms
ms2_1 | 64 bytes from 172.22.0.3: seq=3 ttl=64 time=0.137 ms
ms1_1 | 64 bytes from 172.22.0.2: seq=3 ttl=64 time=0.113 ms
ms2_1 | 64 bytes from 172.22.0.3: seq=4 ttl=64 time=0.246 ms
ms1_1 | 64 bytes from 172.22.0.2: seq=4 ttl=64 time=0.115 ms
ms2_1 | 64 bytes from 172.22.0.3: seq=5 ttl=64 time=0.078 ms
并且还创建了网络并且可以列出:
ubuntu@ubuntu:~/docker_compose_tests/test$ docker network ls
NETWORK ID NAME DRIVER SCOPE
c8562a9231c3 bridge bridge local
412040f6cf69 host host local
1cbabce12616 none null local
59de206c1ffa test_docker_dev_cloud bridge local