Skip to content

noveogroup-amorgunov/docker-compose-postgres

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

docker-compose-postgres

Easy way work with postgres using docker-compose.

  • Firstly, install docker and docker-compose.
  • Edit postgres-initdb.sh file (change user/password and database name as you want):
#!/bin/sh -e

psql --variable=ON_ERROR_STOP=1 --username "postgres" <<-EOSQL
    CREATE ROLE events WITH LOGIN PASSWORD 'events';
    CREATE DATABASE "events-api" OWNER = events;
    GRANT ALL PRIVILEGES ON DATABASE "events-api" TO events;
EOSQL
  • Edit exported port in docker-compose.yml (if you want):
postgres:
  ports:
    - '5436:5432' # 5436 <- change this value
  restart: always
  image: postgres:9.6.5-alpine
  volumes:
    - ./postgres-initdb.sh:/docker-entrypoint-initdb.d/init.sh

Run command docker-compose up or docker-compose up -d to run container as process. To stop container run docker-compose down.

Now you can work with database using follow connection url: postgres://events:events@localhost:5436/events-api.

Solutions for possible problems

docker volume ls
docker volume rm <VOLUME>
  • If you have local postgresql, may be you should turn off postgresql service as:
sudo service postgresql stop

About

Example of using postgres into docker

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages