Skip to content

Instantly share code, notes, and snippets.

@diegoquintanav
Created September 21, 2019 11:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save diegoquintanav/a3c046f016f4887ba8e74859dcb560a7 to your computer and use it in GitHub Desktop.
Save diegoquintanav/a3c046f016f4887ba8e74859dcb560a7 to your computer and use it in GitHub Desktop.
Toy postgres instance with `pgadmin4` and docker compose

Getting a postgres instance with pgadmin4 🐘 and docker-compose 🐳

  1. Use Linux and have docker and docker-compose installed.
  2. Create a folder
  3. Put docker-compose.yml and servers.json
  • Optional: Put a SQL script to be executed at first run from the db service.
  1. docker-compose up -d
  2. Go to 0.0.0.0:5050 and login with test@test.com and test as password
  3. Access the database with the test password
  4. You have a database to play!

To get rid of these containers, use docker-compose down. Pass -v to get rid of any persisted data. In case of doubts, check the docker documentation.

version: "3.7"
services:
db:
# https://hub.docker.com/_/postgres/
image: "postgres:10"
restart: always
environment:
- POSTGRES_PASSWORD=test
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- 5555:5432
networks:
db_nw:
aliases:
- postgres
pgadmin:
image: dpage/pgadmin4:4
restart: always
environment:
- PGADMIN_DEFAULT_EMAIL=test@test.com
- PGADMIN_DEFAULT_PASSWORD=test
volumes:
- ./servers.json:/pgadmin4/servers.json
ports:
- 5050:80
depends_on:
- db
networks:
db_nw:
aliases:
- pgadmin
networks:
db_nw:
driver: bridge
volumes:
pgdata:
{
"Servers": {
"1": {
"Name": "DemoDB",
"Port": 5432,
"Username": "postgres",
"Group": "DEMO",
"Host": "postgres",
"SSLMode": "prefer",
"MaintenanceDB": "postgres",
"Comment": "This server was configured using a JSON. See <https://www.pgadmin.org/docs/pgadmin4/3.6/export_import_servers.html?highlight=servers%20json>"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment