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

1.2K
Vistas
Access localhost and docker network using docker-compose

I have two different services running in a single docker-compose file. I talk to each service by referring to the service name of the containers.

Now I want my container A to access localhost as well. For this when I added the configuration of 'network_mode=host', but this creates an error now stating that container A cannot talk to container B.

version: '2'

services:
  rocketchat:
    image: myimage
    environment:
      - MONGO_URL=mongodb://mongo:27017/dbname
    depends_on:
      - mongo
    ports:
      - 3000:3000
    network_mode: host

  mongo:
    image: mongo:3.2
    ports:
      - 27017:27017

For each compose file docker-compose creates a network so in this case, should I manually assign the containers to a dedicated network as well? Or is there any workaround to access both the networks?

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

0

try to add links :

version: '2'

services:
  rocketchat:
    image: myimage
    environment:
      - MONGO_URL=mongodb://mongo:27017/dbname
    depends_on:
      - mongo
    ports:
      - 3000:3000
    links:
      - mongo
    #network_mode: host

  mongo:
    image: mongo:3.2
    ports:
      - 27017:27017

and you do not need network_mode: host if you use the links

EDIT - Other solution:

version: '2'

services:
  rocketchat:
    image: myimage
    environment:
      - MONGO_URL=mongodb://localhost:27017/dbname
    depends_on:
      - mongo
    ports:
      - 3000:3000
    network_mode: host

  mongo:
    image: mongo:3.2
    ports:
      - 27017:27017
    network_mode: host
over 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