How to Deploy and Run Redis in a Docker container
- Redis Enterprise
Ensure that Docker is installed in your system.
If you're new, refer to Docker's installation guide to install Docker on Mac.
To pull and start the Redis Enterprise Software Docker container, run this
docker run command in the terminal or command-line for your operating system.
On Windows, make sure Docker is configured to run Linux-based containers.
docker run -d --cap-add sys_resource --name rp -p 8443:8443 -p 9443:9443 -p 12000:12000 redislabs/redis
In the web browser on the host machine, go to
https://localhost:8443 to see the Redis Enterprise Software web console.
Step 1: Click on “Setup”
Click Setup to start the node configuration steps.
Step 2: Enter your preferred FQDN
In the Node Configuration settings, enter a cluster FQDN such as demo.redis.com. Then click the Next button.
Enter your license key, if you have one. If not, click the Next button to use the trial version.
Step 3: Enter the admin credentials
Enter an email and password for the admin account for the web console.
These credentials are also used for connections to the REST API. Click OK to confirm that you are aware of the replacement of the HTTPS SSL/TLS certificate on the node, and proceed through the browser warning.
Step 4: Create a Database:
Select “Redis database” and the “single region” deployment, and click Next.
Enter a database name such as demodb and click Activate to create your database
You now have a Redis database!
Step 5: Connecting using redis-cli
After you create the Redis database, you are ready to store data in your database.
redis-cli is a built-in simple command-line tool to interact with Redis databases. Run
redis-cli, located in the
/opt/redislabs/bin directory, to connect to port 12000 and store and retrieve the value of a key in the database:
$ docker exec -it rp bash
/opt/redislabs/bin/redis-cli -p 12000
127.0.0.1:12000> auth <enter password>
127.0.0.1:12000> set key1 123
127.0.0.1:12000> get key1
Ensure that Docker is installed in your system. Follow [Docker's installation guide)[https://docs.docker.com/engine/install/] if you haven’t installed it yet.
Step 1: Run the Redis container
Execute the following command to run Redis container in the background in a “detached” mode.
$ docker run --name myredis -d redis
myredisis the name of Docker container
-drepresentis running Redis in a background in a “detached” mode.
redisis the name of Docker Image that it fetches from Docker Hub.
Step 2: Verify if the Redis container is running or not:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
241f2411637e redis "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 6379/tcp myredis
Step 3: Connect to your database
The following uses the first three alphanumeric characters of your Container ID and opens up
sh shell of the Redis Docker container:
$ docker exec -it 241 sh
Step 4: Testing Redis container
Execute the following command to test the Redis server:
By default, Redis uses 0-15 as indexes for databases, you can change that number in
Step 5: Running Redis container with Persistent Storage
In order to enable persistence, you should invoke the Docker container, passing
appendonly yes option as shown below:
$ docker run --name some-redis -d redis redis-server --appendonly yes
If persistence is enabled, data is stored in the volume
/data, which can be used with
--volumes-from some-volume-container or