Install Redis Inside Docker Container in Linux

Install Redis Inside Docker Container in Linux

Redis is an in-memory key-value data structure store. It often used as a database, cache, and message broker. Redis is an open-source project which released under a 3-clause BSD license.

This tutorial explains how to install Redis inside a Docker container in the Linux. Commands have been tested on Ubuntu.

Prepare environment

Make sure you have installed Docker in your system. If you are using Ubuntu, installation instructions can be found in the post.

Install Redis

  • Host network

Run the following command to create a container for Redis that uses host network:

docker run -d --name=redis --restart=always --network=host \
    -v /opt/redis/data:/data \
    redis
  • User-defined bridge network

User-defined bridge network can be used for listening on different port. By default, Redis service is listening on port 6379. It can be changed with -p option.

docker network create app-net
docker run -d --name=redis --restart=always --network=app-net \
    -p 8080:6379 \
    -v /opt/redis/data:/data \
    redis

Testing Redis

Run the following command to open the Redis CLI and execute PING to test whether a connection is alive and the Redis server can serve data.

docker exec -it redis redis-cli PING

Output:

PONG

Uninstall Redis

To completely remove Redis, remove its container:

docker rm --force redis

Remove Redis image:

docker rmi redis

You can also remove Redis data:

sudo rm -rf /opt/redis

If a user-defined bridge network was created, you can delete it as follows:

docker network rm app-net

Leave a Comment

Cancel reply

Your email address will not be published.