Redis is an in-memory key-value store which can save abstract data structures with high performance. The open-source software is typically used for database, messaging, and caching functions.
Docker is the leading toolkit for packaging applications into containers. It lets you isolate software components into independent environments with their own filesystem.
In this guide, we’ll use Docker to quickly deploy Redis using the official image on Docker Hub. Compared to bare metal installation, Docker enables a simpler set up procedure and won’t pollute your host with new packages. Make sure you’ve got a functioning Docker installation on your host before you continue.
Create a Redis container
We can create an instance of Redis running in a container by pulling the image in the Docker.
Shown below is the command syntax we’ll use in Docker to create the Redis database container:
docker run --name my-redis -p 6379:6379 -d redis
In this command
--name
sets the name of our container and though it’s completely optional, it helps you find your container more easily in case you run multiple containers or you want to connect to it
-p
maps the port 6379 from our machine to the same port in the container, so we can connect to the database from outside the container on that port
-d
specifies that the container should run in detached mode which you can think of it as running the container in the background.
We can confirm Redis Docker is running by using docker ps:
~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d7c0d2191f51 redis "docker-entrypoint.s…" 3 seconds ago Up 2 seconds 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp my-redis
Connect to Redis from host
Now, let’s see if we can also connect to Redis from my laptop. First, we need redis-cli (Redis command-line interface) installed locally.
Then, simply do tests again:
~$ redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> exit
I’ll post next parts of this tutorial to show you how to host our code and Redis on utopiops.com . With Utopiops you can just push your code and automatically the build, and deployment happens for you. You can host your applications on Utopiops directly or on your own cloud platform and simply manage it by Utopiops.
Top comments (2)
Please stop using images without tags. Ever. Today (2022.01.23 11:36 EST) your command installs 6.2.6 in hypothetical half-a-year it will be 7.0. For some people who used some tutorial like this in the (distant) past it may be something like 5.0 which can miss some features. Also there is a difference between default debian-based option and alpine one (at least in side 40M vs 10M)
This piece does not cover restarts, persistence, replicas, cluster, any configuration (at least eviction policy and maxmemory). And this certainly does not cover any deployment whatsoever
also
in text you use default 6379