1

In the docker compose file i added api server as a service and mongodb is installed in my local pc. But when the api run in docker container it could not connect with 127.0.0.1:27017.

Here is the docker-compose file.

networks:
  test_network:
    name: test_network
    driver: bridge
services:
  api:
    container_name: api
    build: ./api
    ports:
      - "3031:3031"
    networks:
      - test_network

Why this problem is happening and how i can resolve this problem ?

2
  • 1
    To connect outside a docker container instead of localhost or 127.0.0.1 try this host.docker.internal Commented Aug 26, 2021 at 13:40
  • For more info on troubleshooting checkout this stackoverflow.com/questions/24319662/… Commented Aug 26, 2021 at 13:41

1 Answer 1

1

It happens because the IP address 127.0.0.1:27107 refers to the container itself.

You have to address the above port, but the host ip as I explained here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.