As a follow up to Linking Docker Containers
I've linked both a mongo, redis container with my nodejs app container successfully. My node app is now running inside my container but for some reason I can't access it:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3f8790bb7cc5 mseay/myapp:latest "/bin/bash" 2 minutes ago Up 2 minutes 0.0.0.0:3000->3000/tcp myapp
5470cdd876eb redis:latest "/entrypoint.sh redi About an hour ago Up About an hour 6379/tcp redis
36c61197d8bd mongo:latest "/entrypoint.sh mong About an hour ago Up About an hour 27017/tcp mongo
Inside my container, my node app is running on port 3000. My docker run command specifies to map 3000 in my container to 3000 on my host:
docker run -i -t -p 3000:3000 --name myapp --link mongo:MONGODB --link redis:REDIS mseay/myapp /bin/bash
docker port shows
3000/tcp -> 0.0.0.0:3000
But, when I goto localhost:3000 or try to curl it:
curl: (7) Failed to connect to localhost port 3000: Connection refused
Apologies for being noobish. Any help is always greatly appreciated!
The issue is that you're using boot2docker. The ports are published on the virtual machine running docker. You can get the ip address of that vm by running boot2docker ip.
So, for your service on port 3000, you could run:
curl http://$(boot2docker ip):3000/
Related
If I run my docker container with:
docker run -it -p 5432:5432 postgres-words
Output of docker ps
CONTAINER ID IMAGE COMMAND STATUS PORTS NAMES
512416e853e1 postgres-words "docker-entrypoint.s…" Up 5 seconds 80/tcp, 0.0.0.0:5432->5432/tcp, :::5432->5432/tcp busy_chatelet
But with docker run -it -p 0.0.0.0:5432:5432 postgres-words,
docker ps reports:
CONTAINER ID IMAGE COMMAND STATUS PORTS NAMES
44131e2fa6ff postgres-words "docker-entrypoint.s…" Up 4 seconds 80/tcp, 0.0.0.0:5432->5432/tcp festive_chandrasekhar
My question is that what is the significance/meaning of extra :::5432->5432/tcp in the first case.
:::5432->5432/tcp is referring to IPv6. :: in IPv6 has the same meaning as 0.0.0.0 in IPv4, because you can omit zeros in an IPv6 address and replace them with ::. It is also called the unspecified address. For reference you can also look at this question.
I start my docker container with:
docker run -it --expose 10001 --expose 8080 -p 10001:10001 -p 8080:8080 -p 80:80 --rm lucchi/covid90/100e
My docker -ps then has:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1521e0c3d947 lucchi/covid90/100e "/bin/sh -c /bin/bash" 2 seconds ago Up Less than a second 0.0.0.0:80->80/tcp, 0.0.0.0:8080->8080/tcp, 0.0.0.0:10001->10001/tcp funny_panini
But I can't connect to localhost from inside the container. I tried:
curl 0.0.0.0:8080
curl 127.0.0.1:8080
curl https://localhost:8080
but keep getting
curl: (7) Failed to connect to localhost port 8080: Connection refused
Most of the asnwers I read are about adding -p to the run command, I don't get what I'm missing.
Are you trying to connect inside the container?
If not, you may fight this other unrelated question (covering the outside container case) helpful:
From inside of a Docker container, how do I connect to the localhost of the machine?
Is the a server process running inside the docker on the specified port ?
If the app logs are enabled you can get the logs of the container by executing the below command.
docker logs <container_name>
Additionally for ensuring if the app is up and running fine, try doing a curl
from inside of the docker container. You can use the docker exec command to execute any command inside the container.
Something simillar (Unable to connect to MYSQL from Docker Instance and redis connect timeout to remote server in a docker and Calling redis-cli in docker-compose setup) I tried to run for the Redis on Docker.
I start the Docker service like this: docker run --name some-redis -d redis
Output:
docker run --name some-redis -d redis
d2ea8a77ba543b3e85020de6bc450e0d50ce9f60e0307e52fd4ae394bd29722
I re-verified using
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d2ea8a77ba54 redis "docker-entrypoint.sh" 6 minutes ago Up 6 minutes 6379/tcp some-redis
1be4f5dde2fb mysql/mysql-server:latest "/entrypoint.sh mysql" About an hour ago Up About an hour (healthy) 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
e7d9e3713f5c ubuntu "/bin/bash" 6 days ago Up 6 days angry_hodgkin
When I execute the below commands, its not working
docker exec -it redis redis-cli
Error response from daemon: No such container: redis
You named your container some-redis and are trying to connect with the name redis.
Try docker exec -it some-redis redis-cli
Im using docker registry and the docker frontend is listed as running when I invoke docker ps but it is not available at localhost:80:
e2a54694e434 konradkleine/docker-registry-frontend "/bin/sh -c $START_S 26 seconds ago Up 2 seconds 443/tcp, 0.0.0.0:8080->80/tcp serene_tesla
Do you use boot2docker or docker-machine? If so, you should use the VMs IP address instead of localhost.
for boot2docker usually 192.168.59.103.
for docker-machines IP address type docker-machine ip <yourmachine>.
Im running boot2docker. I have a container running which Ive opened port 8000 for. i.e
docker#boot2docker:/home/djangoapp/testtools$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4c52d46227f2 felix001/djangoapp:1.0 "/bin/bash" 22 hours ago Up 22 hours 127.0.0.1:8000->8000/tcp ecstatic_noyce
However if I try to access the port I get a RST,
docker#boot2docker:/home/djangoapp/testtools$ curl http://127.0.0.1:8000
curl: (56) Recv failure: Connection reset by peer
Any ideas ?
You need to use the IP address of the boot2docker VM. Usually 192.168.59.103.
Have you tried seeing if the server is running?
First, you are going to need to root into the container:
docker exec -it 4c52d46227f2 bash
Then, check if the server is running:
python manage.py runserver 0.0.0.0:8000
And, it might be something else other than manage.py for your container, but you get the idea.
Here is another article to help out to understand the manual process and setup: https://ochronus.com/docker-primer-django/