Why can't I ping my docker container?

I am launching a docker container called redis. I want to use the redis redis service, but I cannot execute the ping container!

As shown in the picture, my "redis" container is the IP address 172.17.0.15, but I cannot connect to it.

I want to use redis services. What is wrong with my configuration?

enter image description here

+6
source share
1 answer

Because you are not on the same network. Containers run on their own network by default, separate from the host network.

If you run:

docker run -it debian ping 172.17.0.15 

You should find this to work. Even better, you can bind containers and access them by name:

 $ docker run -d --name redis redis $ docker run --link redis:redis redis redis-cli -h redis ping PONG 

If you really want to access redis from your host, just publish the port through the host:

 $ docker run -d -p 6379:6379 redis 

Now you can contact him on localhost:6379 on the host.

+13
source

All Articles