How to Deploy and Run Redis in a Docker container
- Redis Enterprise
- Redis
#
Pre-requisitesEnsure 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.
Note: On Windows, make sure Docker is configured to run Linux-based containers.
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 FQDNIn 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 credentialsEnter 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-cliAfter 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:
#
Pre-requisitesEnsure 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 containerExecute the following command to run Redis container in the background in a “detached” mode.
where:
myredis
is the name of Docker container-d
representis running Redis in a background in a “detached” mode.redis
is the name of Docker Image that it fetches from Docker Hub.
#
Step 2: Verify if the Redis container is running or not:#
Step 3: Connect to your databaseThe following uses the first three alphanumeric characters of your Container ID and opens up sh
shell of the Redis Docker container:
#
Step 4: Testing Redis containerExecute the following command to test the Redis server:
Please note: By default, Redis uses 0-15 as indexes for databases, you can change that number in redis.conf
.
#
Step 5: Running Redis container with Persistent StorageIn order to enable persistence, you should invoke the Docker container, passing appendonly yes
option as shown below:
If persistence is enabled, data is stored in the volume /data
, which can be used with --volumes-from some-volume-container
or -v /docker/host/dir:/data