Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

330
Vistas
how to run two microservices on same network?

I am facing an 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: 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

i am trying to run the service on docker_dev_cloud but its not running on that network

when i do docker network ls

 ms1_docker_dev_cloud 
   ms2_docker_dev_cloud

Any Help Appreciated, Thanks in Advance

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

edit:

The OP used 2 different .yaml files and 2 different networks were being created maybe because docker-compose uses as project name (by default) the name of the directory with the docker-compose.yaml file. In the comments it was proposed to use:

docker-compose -p project_name up

original answer:

I have changed your yaml a little bit in order to make something that works and can be demonstrated.

  1. I have used the alpine image
  2. I have changed one of the two 8900 ports to 8901 because you can't bind it twice (you can run as many containers as you want making use of their 8900 port but your host has only one 8900 port).
  3. I added entrypoint: ping msX in order to show you that they ping each other.

docker-compose.yaml (run it with 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

you can see that it works, because ms1 - ms2 actually ping each other.

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

and the network is also created and can be 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
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda