Logo AppDev24 Login / Sign Up
Sign Up
Have Login?
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Login
New Account?
Recovery
Go to Login
By continuing you indicate that you agree to Terms of Service and Privacy Policy of the site.
Docker

Docker Redis Container

Updated on Aug 15, 2024

Are you looking to set up a Redis container using Docker on your MacOS machine? Look no further! In this article, we'll walk you through the process of creating and configuring a Docker Redis container, including starting the container, and testing the database.

Step 1: Create a Docker Compose File

We'll create a Docker compose file that defines our Redis container.

redis-docker-compose.yml

services:
  redis-db:
    # Apple M1 Chip
    # platform: linux/amd64
    image: redis:7-alpine
    container_name: redis-db
    restart: always
    ports:
      - 6381:6379
    command: redis-server --save 60 1 --loglevel warning --requirepass Password1234
    volumes:     
      - redis_datadir:/data
    networks:
      - backend-network

networks:
  backend-network:
    driver: bridge

volumes:
  redis_datadir:

This file defines a single service, redis-db, which uses the official Redis 7-alpine image and maps port 6381 on your local machine to port 6379 in the container. The redis database authentication password set as Password1234.

Step 2: Start the Container

Now that we have our environment file and Docker compose file set up, it's time to start the container! Run the following command:

docker-compose -f redis-docker-compose.yml up -d

This will start the container in detached mode, meaning it will run in the background.

Step3: Test Redis Database Container

Once the container is running, we can test our database. Run the following commands:

Let us create some keys & values. 

Note: you should have redis-cli Client installed locally.

db_password=Password1234

redis-cli -h 127.0.0.1 -p 6381 -a ${db_password}

> set "Key1" "Value1"
> set "Key2" "Value2"
> SAVE
> exit

Test the database keys-

redis-cli -h 127.0.0.1 -p 6381 -a ${db_password}

> select 1
> keys *
> get "Key1"
> get "Key2"
> exit

Step 4: Stop the Container

Finally, we can stop the container by running the following command:

docker-compose -f redis-docker-compose.yml down

This will stop the container and remove it from memory.

That's it! We've successfully created and configured a Docker Redis container.

PrimeChess

PrimeChess.org

PrimeChess.org makes elite chess training accessible and affordable for everyone. For the past 6 years, we have offered free chess camps for kids in Singapore and India, and during that time, we also observed many average-rated coaches charging far too much for their services.

To change that, we assembled a team of top-rated coaches including International Masters (IM) or coaches with multiple IM or GM norms, to provide online classes starting from $50 per month (8 classes each month + 4 tournaments)

This affordability is only possible if we get more students. This is why it will be very helpful if you could please pass-on this message to others.

Exclucively For Indian Residents: 
Basic - ₹1500
Intermediate- ₹2000
Advanced - ₹2500

Top 10 Articles