Dockerize redis on Mac with bash scripts for quick access


2 min read

Dockerize redis on Mac with bash scripts for quick access

Run a Redis instance in a docker container to develop applications using the key-value store. Use Homebrew to install docker.


  • Use package manager homebrew brew --version

  • Install docker with homebrew brew install docker

  • Check docker install docker -v

  • Store scripts in /scripts (will assume this as root for bash scripts later).

Dockerfile for our Redis & redis-insight service

  • Create redis-insight.yml in the scripts folder.

  • Open the file in your text/code editor of choice.

version: '3'

    image: redis
    restart: always
      - redis-data:/data
      - 6379:6379
      - redis-network

    image: redislabs/redisinsight:latest
    restart: always
      - 8001:8001
      - REDIS_URI=redis://redis:6379
      - redis-network


  • Define 2 services redis and redis-insight, and expose them on desired ports (used default here).

  • Define default volume to persist the data store, and define networks with the name of choice.

  • Script setup is done, now time for bash scripts to execute this file and spin up or tear down this container.

Bashrc or Zshrc scripts to interact with the container

  • Open .bashrc or .zshrc in the text/code editor of choice

  • Add aliases to spin up or tear down the docker container through the above script

      alias redis-up='cd ~/scripts && docker-compose -f redis-insight.yml up -d && cd -'
      alias redis-down='cd ~/scripts && docker-compose -f redis-insight.yml down && cd -'
  • redis-up spins up the docker container with redis key-value store and redis-insight to interact with redis instances through a GUI

  • redis-down tears down the container

  • Run source ~/.zshrc to reload the shell, get access to aliases

Play around with the script, and see what we get

  • Run redis-up, first-time docker will pull images required to run the container and start the services.

  • Open the browser, and navigate to localhost:8001 to access the Redis-insight gui

  • Enter hostname, port, databaseName at the prompt of redis-insight, gain access to the dashboard

  • Works? Nice! All set to develop Redis applications.

  • Next, run redis-down, to stop the container and tear down the services running in it.

  • Ensure no running container for these services run docker ps

We are Ready-is, ha!

We keep our host file system clean and do not pollute the local development environment scope by installing any dependencies on the local machine. We can take this a step further and write different docker scripts and bash aliases to run different services for development purposes.

I'm all set to develop redis based services locally and maybe later package the whole environment and application in a docker container.