Jayram Kumar
Jayram Kumar

Reputation: 712

mongodb in docker ERR_CONNECTION_TIMED_OUT

Please help me with this. I tried the following steps, but I am not able to connect to MongoDB.

  1. RUN: docker run -p 27017:27017 --name my-mongo -d mongo:latest
  2. RUN: docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' my-mongo
  3. The output of the above command is an IP-Address. Let the IP-Address is 172.17.0.2.
  4. Open in browser this link: http://172.17.0.2:27017/
  5. If the following output is displayed in a browser then everything is fine: It looks like you are trying to access MongoDB over HTTP on the native driver port. I am stuck here.

Thanks

Upvotes: 0

Views: 1073

Answers (1)

Esteban Garcia
Esteban Garcia

Reputation: 2283

The IP Address you are trying to access is the container's private ip that is only accessible from within the docker network.

Using the parameter -p that you're specifying on the docker run you're telling docker to map a local port on your host to the port specified on the container, in this case local port 27017 to container port 27017 and after that you can access it with localhost: http://localhost:27017

Read more about this here: https://docs.docker.com/config/containers/container-networking/

Upvotes: 1

Related Questions