Last active
August 17, 2019 21:30
-
-
Save bdurrani/742f14c3157fd7df4a6e84c9ffca90b5 to your computer and use it in GitHub Desktop.
pgAdmin and postgres docker compose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker run --rm --volumes-from postgres_container -v C:\deletethis\postgres\:/backup ubuntu tar cvf /backup/backup.tar /var/lib/postgresql/data | |
One way to persist data is to use a custom volume | |
https://stackoverflow.com/questions/41637505/how-to-persist-data-in-a-dockerized-postgres-database-using-volumes | |
``` | |
docker volume create pgdata | |
docker run -p 5432:5432 -v pgdata:/var/lib/postgresql/data --name postgres_container --network postgres-docker_postgres -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password --volumes-from=data-container postgres | |
``` | |
Now when you restart the postgres docker container, the data will persist | |
Another optin | |
Copy data over | |
// https://medium.com/@sharmaNK/build-postgres-docker-image-with-data-included-489bd58a1f9e | |
docker exec postgres_container /bin/bash -c "mkdir /postgres && cp -r /var/lib/postgresql/data/* /postgres" | |
docker commit postgres_container postgres_with_data:latest | |
docker run -p 5432:5432 -e PGDATA=postgres --name postgres_container --network postgres-docker_postgres -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password postgres_with_data:latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3.5' | |
services: | |
db: | |
container_name: postgres_container | |
image: postgres | |
ports: | |
- '5432:5432' | |
environment: | |
POSTGRES_USER: 'postgres' | |
POSTGRES_PASSWORD: 'hunter2' | |
networks: | |
- postgres | |
restart: unless-stopped | |
pgadmin: | |
container_name: pgadmin_container | |
image: dpage/pgadmin4 | |
environment: | |
PGADMIN_DEFAULT_EMAIL: ${PGADMIN_DEFAULT_EMAIL:-pgadmin4@pgadmin.org} | |
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_DEFAULT_PASSWORD:-admin} | |
ports: | |
- '${PGADMIN_PORT:-5050}:80' | |
networks: | |
- postgres | |
restart: unless-stopped | |
networks: | |
postgres: | |
driver: bridge | |
# use host.docker.internal as the host name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment