Can't connect to Docker container

Oscar Godson

I have a Node.js service built with Restify and I'm trying to use Docker to wrap it all up. My Dockerfile seems to work fine and my DB and Service boots and using docker exec I can curl REST endpoints just fine. However, the ports don't seem to get exposed. I'm on a Mac if that matters. Here's my Dockerfile:

FROM ubuntu:14.04
MAINTAINER Oscar Godson

RUN apt-get update
RUN apt-get install -y nodejs-legacy
RUN apt-get install -y npm
RUN apt-get install -y mysql-server
RUN apt-get install -y mysql-client

COPY . /src
WORKDIR /src

RUN cd /src;npm install

EXPOSE 4000

CMD ./bin/installer.sh

Here's installer.sh:

service mysql start
mysql -u root < ./bin/demo-data.sql
node index.js

Note: The MySQL DB is purely for testing and local dev. We use AWS RDS for production so thats why its using root access.

Now if I do:

docker run -p 4000:4000 86d57dae4522

And then:

curl http://localhost:4000/blah/ECC4E1D9-0E3C-4CE4-9D5B-2F2649A8F2FD

I get:

curl: (7) Failed to connect to localhost port 4000: Connection refused

If I do it within the container with exec like:

docker exec -i 86d57dae4522 curl http://localhost:4000/blah/ECC4E1D9-0E3C-4CE4-9D5B-2F2649A8F2FD

I get (this is expected since I havent logged into my service):

{"message":"You don't have permissions to do that"}

Within my Restify server I did 0.0.0.0 for the host too since I saw some comments about Rails apps needing to set that so I thought I'd try it in Node/Restify but no luck.:

server.listen(process.env.PORT || 4000, "0.0.0.0", function() {
  console.log('%s listening at %s', server.name, server.url);
});

I've also tried a friend suggestion of:

docker run --net="host" 7500cdb

And i read that --hostname puts the IP you pass it into the /etc/hosts so I tried (this is my computers IP)

docker run --hostname="192.168.2.6" 7500cdb

No luck with any of these. Any ideas?

Nathaniel Waisbrot

Yes, it matters very much that you're on a Mac.

Docker doesn't run natively on the Mac, so you're running boot2docker which is setting up a little VirtualBox-based VM. It is that VM that's running Docker. When you forward some host ports, you are forwarding ports on the VM to the container. When you mount a local path on a container, it's a local path on the VM.

In your example, rather than

 http://localhost:4000/blah/ECC4E1D9-0E3C-4CE4-9D5B-2F2649A8F2FD

you need to run

  http://$(boot2docker ip):4000/blah/ECC4E1D9-0E3C-4CE4-9D5B-2F2649A8F2FD

You can also run boot2docker ip and save that address in your /etc/hosts file under a friendly name, if you like. (This can be helpful if your container is going to serve SSL certs).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Can't connect to mySql docker container with JDBC

From Dev

Can't connect to MySQL docker container

From Dev

Docker Container can't connect to the Internet

From Dev

Can't connect to Postgres docker container from Golang container

From Dev

Docker container can't connect to another using a docker network

From Dev

Laravel 5 application can't connect MariaDB engine in docker container

From Dev

Can't Connect to Postgres on Docker Container via pgAdmin

From Dev

Can't connect to MySQL docker container launched via ansible

From Dev

Can't connect Docker Wordpress container to MySQL on host

From Dev

Laravel 5 application can't connect MariaDB engine in docker container

From Dev

Docker container can't connect to server running on localhost

From Dev

jsPlumb can't connect to a container

From Dev

Docker : Drupal container linked to mysql container can't connect to mysql during Drupal installation

From Dev

ManageIQ web application inside Docker container can’t connect to Hawkular outside container

From Dev

Can't connect to MySQL docker container created via docker-compose

From Dev

can't access docker container

From Dev

Can't connect to docker process

From Dev

Docker runs but can't connect

From Java

Docker Can't connect to linked container on the same network - all other containers working

From Dev

Why I can't connect to mysql docker container through JDBC with another database user than root?

From Dev

Symfony docker container don't manage to connect to mariadb container

From Java

Docker command can't connect to Docker daemon

From Dev

Connect to WordPress Docker Container

From Dev

Connect with filezilla to docker container

From Dev

Connect to WordPress Docker Container

From Dev

can't install npm in the docker container?

From Dev

Can't use tc in docker container

From Dev

Can't kill processes (originating in a docker container)

From Dev

hazelcast docker container can't run continuously

Related Related

  1. 1

    Can't connect to mySql docker container with JDBC

  2. 2

    Can't connect to MySQL docker container

  3. 3

    Docker Container can't connect to the Internet

  4. 4

    Can't connect to Postgres docker container from Golang container

  5. 5

    Docker container can't connect to another using a docker network

  6. 6

    Laravel 5 application can't connect MariaDB engine in docker container

  7. 7

    Can't Connect to Postgres on Docker Container via pgAdmin

  8. 8

    Can't connect to MySQL docker container launched via ansible

  9. 9

    Can't connect Docker Wordpress container to MySQL on host

  10. 10

    Laravel 5 application can't connect MariaDB engine in docker container

  11. 11

    Docker container can't connect to server running on localhost

  12. 12

    jsPlumb can't connect to a container

  13. 13

    Docker : Drupal container linked to mysql container can't connect to mysql during Drupal installation

  14. 14

    ManageIQ web application inside Docker container can’t connect to Hawkular outside container

  15. 15

    Can't connect to MySQL docker container created via docker-compose

  16. 16

    can't access docker container

  17. 17

    Can't connect to docker process

  18. 18

    Docker runs but can't connect

  19. 19

    Docker Can't connect to linked container on the same network - all other containers working

  20. 20

    Why I can't connect to mysql docker container through JDBC with another database user than root?

  21. 21

    Symfony docker container don't manage to connect to mariadb container

  22. 22

    Docker command can't connect to Docker daemon

  23. 23

    Connect to WordPress Docker Container

  24. 24

    Connect with filezilla to docker container

  25. 25

    Connect to WordPress Docker Container

  26. 26

    can't install npm in the docker container?

  27. 27

    Can't use tc in docker container

  28. 28

    Can't kill processes (originating in a docker container)

  29. 29

    hazelcast docker container can't run continuously

HotTag

Archive