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
Install docker with homebrew
brew install docker
Check docker install
Store scripts in
/scripts(will assume this as root for bash scripts later).
Dockerfile for our Redis & redis-insight service
redis-insight.ymlin the scripts folder.
Open the file in your text/code editor of choice.
version: '3' services: redis: image: redis restart: always volumes: - redis-data:/data ports: - 6379:6379 networks: - redis-network redis-insight: image: redislabs/redisinsight:latest restart: always ports: - 8001:8001 environment: - REDIS_URI=redis://redis:6379 networks: - redis-network volumes: redis-data: networks: 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
.zshrcin 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-upspins up the docker container with redis key-value store and redis-insight to interact with redis instances through a
redis-downtears down the container
source ~/.zshrcto reload the shell, get access to aliases
Play around with the script, and see what we get
redis-up, first-time docker will pull images required to run the container and start the services.
Open the browser, and navigate to
localhost:8001to access the Redis-insight gui
hostname, port, databaseNameat the prompt of redis-insight, gain access to the dashboard
Works? Nice! All set to develop Redis applications.
redis-down, to stop the container and tear down the services running in it.
- Ensure no running container for these services run
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.