Skip to content

Instantly share code, notes, and snippets.

@peacefixation
Last active July 18, 2019 00:26
Show Gist options
  • Save peacefixation/0ac6f659776361564b10c340faea802a to your computer and use it in GitHub Desktop.
Save peacefixation/0ac6f659776361564b10c340faea802a to your computer and use it in GitHub Desktop.
Docker commands
# https://docs.docker.com/engine/reference/commandline/docker/
name = container_name
dbname = db_name
version = 0.1
# build the container (with name:tag)
build:
docker build -t $(name):$(version) .
# spin the container up (detach, remove on close, forward port, name)
up:
docker run -ti -d --rm -p 5432:5432 --name $(name) $(name):$(version)
# shut the container down (by name)
down:
docker stop $(name)
# open a bash shell in the container
shell:
docker exec -ti $(name) /bin/bash
# connect to the postgres database
conn:
docker exec -ti $(name) /bin/bash -c "su postgres -c \"psql -d $(dbname)\""
# tail (and follow) the container logs
tailf:
docker logs --follow $(name)
# dump the database to a file and copy it back to the host machine
dump:
docker exec -ti $(name) /bin/bash -c "su postgres -c \"pg_dumpall > /tmp/dump.sql\"; mv /tmp/dump.sql /; chmod 755 /dump.sql"; docker cp $$(docker ps -f name="$(name)" -q):/dump.sql .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment