docker - how to run two microservices on same network? -
i facing issue here:
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: 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: networks: - docker_dev_cloud networks: docker_dev_cloud: driver: bridge
i trying run service on docker_dev_cloud not running on network
when docker network ls
ms1_docker_dev_cloud ms2_docker_dev_cloud
any appreciated, in advance
edit:
the op used 2 different .yaml
files , 2 different networks being created maybe because docker-compose
uses project name (by default) name of directory docker-compose.yaml
file. in comments proposed use:
docker-compose -p project_name
original answer:
i have changed yaml
little bit in order make works , can demonstrated.
- i have used
alpine
image - i have changed 1 of 2 8900 ports 8901 because can't bind twice (you can run many containers want making use of 8900 port host has 1 8900 port).
- i added
entrypoint: ping msx
in order show ping each other.
docker-compose.yaml (run 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: 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: networks: - docker_dev_cloud entrypoint: ping ms1 networks: docker_dev_cloud: driver: bridge
you can see works, because ms1 - ms2 ping each other.
ubuntu@ubuntu:~/docker_compose_tests/test$ docker-compose creating network "test_docker_dev_cloud" driver "bridge" creating test_ms1_1 creating test_ms2_1 attaching test_ms2_1, test_ms1_1 ms2_1 | ping ms1 (172.22.0.3): 56 data bytes ms2_1 | 64 bytes 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 172.22.0.2: seq=0 ttl=64 time=0.054 ms ms2_1 | 64 bytes 172.22.0.3: seq=1 ttl=64 time=0.286 ms ms1_1 | 64 bytes 172.22.0.2: seq=1 ttl=64 time=0.113 ms ms2_1 | 64 bytes 172.22.0.3: seq=2 ttl=64 time=0.129 ms ms1_1 | 64 bytes 172.22.0.2: seq=2 ttl=64 time=0.086 ms ms2_1 | 64 bytes 172.22.0.3: seq=3 ttl=64 time=0.137 ms ms1_1 | 64 bytes 172.22.0.2: seq=3 ttl=64 time=0.113 ms ms2_1 | 64 bytes 172.22.0.3: seq=4 ttl=64 time=0.246 ms ms1_1 | 64 bytes 172.22.0.2: seq=4 ttl=64 time=0.115 ms ms2_1 | 64 bytes 172.22.0.3: seq=5 ttl=64 time=0.078 ms
and network created , can listed:
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
Comments
Post a Comment