Unable to connect to Redis from Docker - docker

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

Related

Understanding docker port mapping output of docker ps

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.

Docker swarm - Port not accessible

I am trying out some things with docker and docker swarm and currently I am running into a problem.
If I create a container with:
docker run -d --name my_nginx -p 8080:80 nginx
everythings went fine, I am able to access this port.
If I try to create a service with docker swarm (container was removed before) I am not able to open that port:
docker service create -d --name my_service_nginx --replicas=1 -p 8080:80 nginx
It seems that the service does not create a portmapping.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d3417b80036c nginx:latest "/docker-entrypoint.…" 6 minutes ago Up 6 minutes 80/tcp my_service.1.1l3fwcct1m9hoallkn0g9qwpd
Do you have any idea what I am doing wrong?
Best regards
Jan
Launching a Docker swarm on the LXC is not possible:
Docker swarm get access from outside network

How to get complete Port details of running Container

I am learning Docker as a beginner and I am finding one info confusing. Here is step details:
Pulling Image from Docker Hub
Running Image
Now, I am seeing any Half port details in CLI due to which I am not able to ger proper port ID.
But when I am running same Image through KITEMATIC and checking the status of the running container then it is showing me properly.
Please refer Screenshot below for details:
First Line in shared Pic is showing complete details of PORTs( started container in KITEMATIC)
Second-line is not showing complete.
I want to know the reason for this difference and how to resolve it.
In first line of docker ps, you publish the port using below command
docker run -it -p 32773:80 -p 32772:443 static-site
That is why you are seeing HOST_PORT->Container_PORT, to see the same response on another container you need to publish port
docker run -it --rm -p 80:80 -p 443:443 your_image
80:80 mean HostPort:ContainerPort.
Images can expose a port. This is documentation from the image creator to those using the image. It tells you which ports the application inside the container are listening on by default. When you run a container with an exposed port, but you do not publish it on the host, you'll see only the container port listed in the docker container ls. This is again only documentation at this point, no docker networking has been configured to use that container port, so docker is letting you know that inside the container that application is likely listening on that port:
$ docker run -d --name unpublished --rm nginx
63291688813a75a8d9f0d383b4fbef30e93be8e89bd22fc80c2953da65d1d5e9
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
63291688813a nginx "nginx -g 'daemon of…" 41 seconds ago Up 39 seconds 80/tcp unpublished
If you publish a container to a specific port, you'll see that listed as desired:
$ docker run -d --name exact -p 8080:80 --rm nginx
10f82a87d8dce2226c030ca5f23e7983b0f60673c0ec614302dc129dad4ba86d
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
10f82a87d8dc nginx "nginx -g 'daemon of…" 14 seconds ago Up 12 seconds 0.0.0.0:8080->80/tcp exact
And it looks like kitematic is publishing all ports with the -P flag (capital) which looks at all exposed ports and maps them to unused high numbered ports:
$ docker run -d --name publish_all -P --rm nginx
982afb237756e543820810cbd6366c8fa8569a386ff581cd7edc63557004e8c4
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
982afb237756 nginx "nginx -g 'daemon of…" 3 seconds ago Up 2 seconds 0.0.0.0:32768->80/tcp publish_all
If you want the know what port was published on the host, particularly when you tell docker to use unused high numbered ports, you can query that with the port command, e.g. for the publish_all container above:
$ docker container port publish_all 80
0.0.0.0:32768
You can see the exposed ports with an inspect of the image:
$ docker image inspect nginx --format '{{json .Config.ExposedPorts}}' | jq .
{
"80/tcp": {}
}

docker swarm - unable to connect to nginx container

I have setup Docker swarm on single node and have created a container on it running nginx server but i am unable to connect to nginx server on specified port. Also, i am not able to attach to container. Any help is much appreciated.
[user#hostname yum.repos.d]$ sudo docker swarm init
[user#hostname yum.repos.d]$ sudo docker info | grep -i "swarm: active"
Swarm: active
[user#hostname yum.repos.d]$
[user#hostname yum.repos.d]$ sudo docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
xxxxxxxxxxxxxxx * hostname.server.com Ready Active Leader
[user#hostname yum.repos.d]$ sudo docker service create --name web --publish 8080:80 nginx
[user#hostname ~]$ sudo docker ps -a
[sudo] password for user:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
xxxxxxxxxxx nginx#sha256:ccdb5fdf47709493f9fc5af32478c0d86b3cbee0c306e3f04a0d3e640a50ea2d "nginx -g 'daemon ..." About an hour ago Up About an hour 80/tcp web.1.
[user#hostname ~]$ elinks http://localhost:8080 //says request sent but no response received.
Above elinks command is unable to connect to url.
It works!!
[user#hostname ~]$ sudo docker service ps web
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
xxxxxxxxxxxx web.1 httpd:latest hostname.myserver.com Running Running 3 minutes ago
[user#hostname ~]$
[user#hostname ~]$ elinks http://hostname.mylabserver.com:80
This works and connects to nginx running on port 80.
Thanks!!

Docker port expose

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/

Resources