What goes in "some-network" placeholder in dockerized redis cli?

Viewed 325

I'm looking at documentation here, and see the following line:

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

What should go in the --network some-network field? My docker run command in the field before did default port mapping of docker run -d -p 6379:6379, etc.

I'm starting my redis server with default docker network configuration, and see this is in use:

$ docker container ls
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                    NAMES
abcfa8a32de9        redis               "docker-entrypoint.s…"   19 minutes ago       Up 19 minutes       0.0.0.0:6379->6379/tcp   some-redis

However, using the default bridge network produces:

$ docker run -it --network bridge --rm redis redis-cli -h some-redis
Could not connect to Redis at some-redis:6379: Name or service not known
3 Answers

Ignore the --network bridge command and use:

docker exec -it some-redis redis-cli

You need to run

docker network create some-network

It doesn't matter what name some-network is, just so long as the Redis server, your special CLI container, and any clients talking to the server all use the same name. (If you're using Docker Compose this happens for you automatically and the network will be named something like directoryname_default; use docker network ls to find it.)

If your Redis server is already running, you can use docker network connect to attach the existing container to the new network. This is one of the few settings you're able to change after you've created a container.

If you're just trying to run a client to talk to this Redis, you don't need Docker for this at all. You can install the Redis client tools locally and run redis-cli, pointing at your host's IP address and the first port in the docker run -p option. The Redis wire protocol is simple enough that you can also use primitive tools like nc or telnet as well.

Related