Last active
July 18, 2019 00:26
-
-
Save peacefixation/0ac6f659776361564b10c340faea802a to your computer and use it in GitHub Desktop.
Docker commands
This file contains hidden or 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
# 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