Khamidulla Inoyatov

How to setup Redis easly for development using docker


Prerequisites

In order to install Redis using docker following requirements must be met:

$ docker --version
Docker version 18.06.0-ce, build 0ffa825
$ docker-compose --version
docker-compose version 1.22.0, build f46880fe

Install Redis

Open terminal (Ctrl+Alt+t shortcut to open terminal), and navigate to path where you want to create docker compose project for Redis. Create docker-compose.yml file with following content.

version: "3"

services:
    redis:
        container_name: redis-4.0.11 
        image: redis:4.0.11
        restart: always
        ports:
            - "6379:6379/tcp"

If you noticied we are binding 6379/tcp port to external port. If you want to control port by firewall you should remove ports options from docker compose. Which will limit Redis service to local machine and other docker containers. Moreover if you want to prevent anonymous access to Redis server you can provide password as following example:

version: "3"

services:
    redis:
        container_name: redis-4.0.11 
        image: redis:4.0.11
        restart: always
        command: redis-server --requirepass <password>
        ports:
            - "6379:6379/tcp"

Finally in order to start and stop Redis server in background following command can be executed:

$ docker-compose up -d
$ docker-compose down 

if you will not provide -d option Redis container will be lunched in foreground. That’s all Folks!

comments powered by Disqus