Skip to content

Instantly share code, notes, and snippets.

@lorecrafting
Last active October 30, 2018 22:06
Show Gist options
  • Save lorecrafting/1a62f9d1caef1ebbfa2745589da30577 to your computer and use it in GitHub Desktop.
Save lorecrafting/1a62f9d1caef1ebbfa2745589da30577 to your computer and use it in GitHub Desktop.
Compose Postgres

docker-compose.yml

version: '3'
services:
  db:
    image: postgres:10.0-alpine
    env_file: .env
    volumes:
      - pg-data-volume:/var/lib/postgresql/data
    ports:
      - '${POSTGRES_HOST_PORT}:${POSTGRES_CONTAINER_PORT}'
    networks:
      - my-app-network
volumes:
  pg-data-volume:
networks:
  my-app-network:

.env

POSTGRES_HOST_PORT=5432
POSTGRES_CONTAINER_PORT=5432
POSTGRES_HOSTNAME=db
POSTGRES_USER=username
POSTGRES_PASSWORD=password
POSTGRES_DB=mydb

docker-compose up to bring up services docker-compose down to bring down services docker-compose down -v to delete associated volumes. This deletes db data and initial credentials

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment