Question

Cant access docker from ip address Docker/Node.js

Posted December 16, 2019 6.1k views
Docker

Hello
I have the basic server which I have docker installed. I was able to grab my project off github and install it on the docker server. Everything seemed to work ok. My ip address is http://64.225.0.97:8080/I do not get a connection. Even running it without http://64.225.0.97

22/tcp LIMIT Anywhere

2375/tcp ALLOW Anywhere

2376/tcp ALLOW Anywhere

80/tcp ALLOW Anywhere

443/tcp ALLOW Anywhere

Apache ALLOW Anywhere

8080 ALLOW Anywhere

22/tcp (v6) LIMIT Anywhere (v6)

2375/tcp (v6) ALLOW Anywhere (v6)

2376/tcp (v6) ALLOW Anywhere (v6)

80/tcp (v6) ALLOW Anywhere (v6)

443/tcp (v6) ALLOW Anywhere (v6)

Apache (v6) ALLOW Anywhere (v6)

8080 (v6) ALLOW Anywhere (v6)

too many duplicates. but I had uninstalled apache.
I isntalled node.js to the server as well as docker.

2a19408a0fef project “docker-entrypoint.s…” 2 hours ago Up 2 hours 0.0.0.0:8080->8081/tcp jolly_ptolemy

This is what my status is and I dont have a firewall configured on digitalocean yet but do i need to add anything. Need some help. Thanks

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hello,

Your firewall rules look good. There are no duplicates: one rule is for IPv4 and the second one is for IPv6.

Your Docker container seems to be exposing port 8080 correctly, you need to make sure that the node application inside the container is actually running on port 8080 as well.

How I would usually check what ports I should use, is by running docker inspect followed by the image ID, there you should look for the ExposedPorts section and make sure that it matches the one that you are using.

Hope that this helps!

Regards,
Bobby

  • thanks it says its exposedports is 8081 tcp. but on running from terminal i get this.

    error: cannot connect to mongodb://localhost/demodb
    error: message=failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017], name=MongoError, stack=MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]

    So I may have narrowed it down to this. I have mongodb installed. It is on the localhost but I think this is why nothing is loading. not sure what to do.

    • Hi @xxzjchromexx,

      I think that you would need to change MongoDB to listen on 0.0.0.0 instead of 127.0.0.1 in /etc/mongod.conf.

      After that create a new Docker network:

      docker network create -d bridge --subnet 192.168.0.0/24 --gateway 192.168.0.1 mynetwork
      

      After that connect your container to this network:

      docker network connect mynetwork your_container_name 
      

      After that in your MongoDB connection string in your container make sure to specify 192.168.0.1 as the IP address as the MongoDB instance is running on your host.

      Hope that this helps!
      Regards,
      Bobby

Submit an Answer