Postgres and Redis containers with Docker Compose
Docker Compose facilitates spinning up containers for databases without installing the databases locally. This post covers the setup for Postgres and Redis images.
Prerequisites
- Docker Compose installed
Configuration
The following configuration spins up Postgres and Redis containers with UI tools (Pgweb and Redis Commander).
Connection strings for Postgres and Redis are redis://localhost:6379
and postgres://username:password@localhost:5435/database-name
.
Pgweb and Redis Commander are available at http://localhost:8085
and http://localhost:8081
links.
# docker-compose.ymlversion: '3.8'services:postgres:image: postgres:alpineenvironment:POSTGRES_DB: database-namePOSTGRES_PASSWORD: passwordPOSTGRES_USER: usernameports:- 5435:5432restart: on-failure:3pgweb:image: sosedoff/pgwebdepends_on:- postgresenvironment:PGWEB_DATABASE_URL: postgres://username:password@postgres:5432/database-name?sslmode=disableports:- 8085:8081restart: on-failure:3redis:image: redis:latestcommand: redis-servervolumes:- redis:/var/lib/redis- redis-config:/usr/local/etc/redis/redis.confports:- 6379:6379networks:- redis-networkredis-commander:image: rediscommander/redis-commander:latestenvironment:- REDIS_HOSTS=local:redis:6379- HTTP_USER=root- HTTP_PASSWORD=qwertyports:- 8081:8081networks:- redis-networkdepends_on:- redisvolumes:redis:redis-config:networks:redis-network:driver: bridge
Run the following command to spin up the containers.
docker-compose up
Course
Build your SaaS in 2 weeks - Start Now