I am trying to run redis with persistence storage. I followed official docker page of redis fo installation.
I pulled the image using –
docker pull redis
I started redis with persistence storage using –
docker run --name some-redis -d redis redis-server --appendonly yes
And I am tring to connect to redis instance with redis cli with –
docker run -it --network some-network --rm redis redis-cli -h some-redis
It gives me following error –
docker: Error response from daemon: network some-network not found.
I am following the documentation to the point, why is this not working?
3
Answers
First create the network
then use it in all your containers that have to use the network.
When you have finished remove the network.
First ,you this command run as redis-server
Next,you want run redis-cli to connect redis-server
should be attach redis-server container and run redis-cli
Of course, if you want to access through the network like a redis page, you need to attach the network of the cli’s container to the redis-server container to share the network
Both answers give interesting information but lack the main thing.
In docker, containers may connect to some networks.
By default if you don’t specify any network when you run a container, it will use the default bridge network : inside that network any container can communicate with any other but only via their ip addresses.
You cannot communicate between containers of that network via container name.
So here
docker run -it --network some-network --rm redis redis-cli -h some-redis
, thesome-redis
part is not a resolvable hostname.To overcome that, you have to refer the container by its ip address.
Inspect the container to know that :
You should get something like :
"IPAddress": "172.17...."
Now specify the ip address as -h parameter and it should be fine :
That is really not a net/reusable/portable way to make two containers to communicate each other. That is more suitable to experiment things.
You can communicate between containers of that network via container name.
Create your network :
Run the redis server and connect it to that network :
Run the redis client and connect it to that network :
Now the client can connect to the server instance via
-h some-redis
.