Redis is an open-source, fast, and in-memory key-value data store. It can be used as a database, cache, message broker, and queue. Redis is designed for distributed cluster environment and it can handle large datasets. Deploying Redis in a Docker container will help to scale Redis and fit it right into your development environment.
In this post, we will show you how to deploy Redis with Docker on Ubuntu 20.04.
- A fresh Ubuntu 20.04 server on the Atlantic.Net Cloud Platform
- A root password configured on your server
Step 1 – Create Atlantic.Net Cloud Server
First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing Ubuntu 20.04 as the operating system with at least 4GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.
Once you are logged in to your Ubuntu 20.04 server, run the following command to update your base system with the latest available packages.
apt-get update -y
Step 2 – Install Docker
By default, the latest version of Docker is not included in the Ubuntu default repository, so you will need to add the Docker official repository to your system.
First, install all required dependencies using the following command:
apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common -y
Next, add the Docker repository with the following command:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Once the repository is added, install Docker with the following command:
apt-get install docker-ce -y
Once Docker is installed, check the status of Docker with the following command:
systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2021-06-07 07:14:36 UTC; 13s ago
TriggeredBy: ● docker.socket
Main PID: 9081 (dockerd)
└─9081 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Step 3 – Download Redis Image
Next, you will need to download the latest version of the Redis image from the Docker registry. You can download it with the following command:
docker pull redis:latest
latest: Pulling from library/redis
69692152171a: Pull complete
a4a46f2fd7e0: Pull complete
bcdf6fddc3bd: Pull complete
2902e41faefa: Pull complete
df3e1d63cdb1: Pull complete
fa57f005a60d: Pull complete
Status: Downloaded newer image for redis:latest
You can now verify the downloaded image with the following command:
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest fad0ee7e917a 5 days ago 105MB
Step 4 – Launch Redis Container
Next, you will need to launch a Redis container from the downloaded image. You can launch it with the following command:
docker run --name redis-instance -dit redis
Once the container is started, you can check it with the following command:
You should see the following output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2e7b27647159 redis "docker-entrypoint.s…" 11 seconds ago Up 9 seconds 6379/tcp redis-instance
As you can see, the Redis container is started and listening on port 6379.
Step 5 – Connect the Redis Container
Next, you can connect to the Redis container with the following command:
docker exec -it redis-instance /bin/bash
Once you are connected, you should see the following shell:
Now, connect to the Redis interface with the following command:
[email protected]:/data# redis-cli
Now, test the Redis with the ping command:
If everything is fine, you should see the following output:
Run the quit command to exit from the Redis CLI.
Next, exit from the Redis container with the following command:
[email protected]:/data# exit
Congratulations! You have successfully deployed a Redis within a Docker container. You can now use this setup to deploy and scale a Redis within a Docker cluster on your dedicated hosting account from Atlantic.Net.