Skip to content

Instantly share code, notes, and snippets.

@Grace-Amondi
Created March 30, 2021 14:52
Show Gist options
  • Save Grace-Amondi/596c36e599c979f373c80fe5e17c7bee to your computer and use it in GitHub Desktop.
Save Grace-Amondi/596c36e599c979f373c80fe5e17c7bee to your computer and use it in GitHub Desktop.

Quick Docker Commands

Initialize database on cmd

docker exec -it <DB_CONTAINER> psql -U <DB_USER> <DB_NAME> 

Backup postgres table

sudo docker exec -it <DB_CONTAINER> pg_dump -U <DB_USER> -t <DB_TABLE> <DB_NAME> > 'path_to_ouput.sql'

Backup postgres database

docker exec -t <DB_CONTAINER> pg_dumpall -c -U <DB_USER> | gzip > ./tmp/dump_$(date +"%Y-%m-%d_%H_%M_%S").gz

Restore database backups

gunzip < your_dump.sql.gz | docker exec -i <DB_CONTAINER> psql -U <DB_USER> -d <DB_NAME>

Create the Docker images

docker-compose build

Run docker machine+containers

docker-compose up

To run the containers in the background

docker-compose up -d

Access to the running machine (mukau-web or any container name, the one defined in docker-compose.yml)

docker exec -it <CONTAINER> bash

Stop the Docker machines

docker-compose stop

Stop and clean docker

To stop and remove everything including volumes run (reset). NOTE: This will result in lose of any data save to the database

docker-compose down --volumes

Copy file from remote server to local

scp -i <path_to_pem_file> <user>@<ip_address>:<path_to_input_file> <path_to_output_directory_location>

Update a postgres table

UPDATE courses
SET published_date = '2020-08-01' 
WHERE course_id = 3;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment