skip to Main Content

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


  1. First create the network

    docker network create some-network
    

    then use it in all your containers that have to use the network.

    docker run --network some-network
    

    When you have finished remove the network.

    docker network rm some-network
    
    Login or Signup to reply.
  2. First ,you this command run as redis-server

    docker run --name some-redis -d redis redis-server --appendonly yes
    

    Next,you want run redis-cli to connect redis-server
    should be attach redis-server container and run redis-cli

    docker exec -it some-redis redis-cli -h
    

    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

    docker run --rm -it --net=container:some-redis  redis redis-cli -h
    
    Login or Signup to reply.
  3. 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.

    1. With the default bridge network

    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, the some-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 :

    docker container inspect some-redis | grep -i ipaddress
    

    You should get something like : "IPAddress": "172.17...."

    Now specify the ip address as -h parameter and it should be fine :

    docker run -it --network some-network --rm redis redis-cli -h 172.17...
    

    That is really not a net/reusable/portable way to make two containers to communicate each other. That is more suitable to experiment things.

    1. With a custom bridge network

    You can communicate between containers of that network via container name.

    Create your network :

    docker network create redis-network
    

    Run the redis server and connect it to that network :

    docker run --name some-redis -d --network redis-network redis redis-server --appendonly yes
    

    Run the redis client and connect it to that network :

    docker run -it --rm --network redis-network redis redis-cli -h some-redis
    

    Now the client can connect to the server instance via -h some-redis.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search