Last active
February 18, 2021 01:40
-
-
Save tristanlins/4491f54ba06d18661fe2204592cdf54e to your computer and use it in GitHub Desktop.
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
# @file /etc/systemd/system/docker-postgres.service | |
# @see https://docs.docker.com/articles/host_integration/ | |
[Unit] | |
Description=postgres container | |
Requires=docker.service | |
After=docker.service | |
[Service] | |
Restart=always | |
ExecStart=/usr/bin/docker start -a postgres | |
ExecStop=/usr/bin/docker stop -t 60 postgres | |
[Install] | |
WantedBy=multi-user.target |
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
# start container | |
sudo systemctl start docker-postgres | |
# stop container | |
sudo systemctl stop docker-postgres | |
# attach shell to container | |
docker exec -it postgres bash | |
# start psql connection | |
docker exec -it postgres psql -h postgres -U postgres | |
# dump a database | |
docker exec postgres pg_dump -h postgres -U postgres ${table} | |
# see the logs | |
docker logs postgres | |
# for more see | |
# https://hub.docker.com/_/postgres/ | |
# https://docs.docker.com/articles/host_integration/ |
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
# create config and data directory | |
mkdir -p $HOME/docker/postgres/data | |
# initially create the docker container | |
docker run --restart=on-failure:5 \ | |
--volume=$HOME/docker/postgres/data:/var/lib/postgresql/data \ | |
--env=POSTGRES_PASSWORD=secret \ | |
--publish=5432:5432 \ | |
--hostname=postgres \ | |
--name=postgres \ | |
--detach=true \ | |
postgres:latest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment