Making a Manual Connection to Redis Server

In this lesson, we will manually connect to the Redis server using a command.

Manually connecting to the Redis server

We have just started Redis using Compose and have seen from the output that it is running. However, since we are still getting familiar with Docker, let’s manually connect to the Redis server and interact with it to prove to ourselves that it really does work.

Using Redis command-line interface

A quick way to do this manually is by using the Redis command-line interface redis-cli. We can leverage the same redis image that already has redis-cli installed. Handy!

Rather than having to set up a new, separate service in Compose, we can piggyback on the existing redis service, since it uses the redis image we need. We can run redis-cli and connect to our Redis server with the following command:

$ docker-compose run --rm redis redis-cli -h redis

Command explanation

This command says, “In a throwaway container (--rm) for the redis service, run the command redis-cli -h redis.” On running it, you will be able to see the standard Redis prompt showing the hostname and port it’s running on.

🍀 Practice

Feel free to play around in the terminal below. For example, try running the ping command, which should give you the “PONG” response. When you’re done, exit with the command quit. This will terminate the Redis client and, as a result, the container.

Also, run the following command after quit:

docker network ls

This will provide you with the list of networks created.

Get hands-on with 1400+ tech skills courses.