📑
Chris Johnson's KB
  • Chris Johnson's KB
  • Meta
    • Pages to Add
  • Cheat Sheets
    • Apache
    • Docker
    • Gatsby
    • Git
    • GraphQL
    • iOS
    • MySQL
    • Nginx
    • NextJS
    • NodeJS
    • Rails
    • React
    • Security Tools
    • Shell (Linux)
    • SwiftUI
    • Ubuntu Server
    • Vim
  • Computing
    • Mac
    • iOS
    • ChromeOS
    • Windows
    • Browser Plugins
    • RSI Prevention
    • Voice Control
    • AWS Cloud 9
    • Visual Studio Code
    • Linux
  • Workflows
    • Podcasting
    • Setting up a new Mac
    • Site Deploys
  • Hardware
    • Dell U2720Q Monitor
    • Moonlander Keyboard
    • Apple Silicon Macs
  • Productivity
    • Structure
    • Nuggets of Wisdom
  • Coffee
    • Coffee Notes & Equipment
    • Coffee Beans
    • AeroPress Recipes
    • V60 Recipes
    • Moka Pot Recipes
    • French Press Recipes
  • Gaming
    • Rocket League
  • Food
    • Cocktails
    • Favorite Recipes
    • Whisky Reviews
    • Infinity Bottle
    • Favorite Wines
  • Inspiration
    • Quotes
  • Philosophy
    • Life
    • Programming
  • Fitness
    • Diets
    • Exercise Notes
    • Personal Training Notes
Powered by GitBook
On this page
  • Dumping and restoring postgres databases in Docker
  • Documentation links:

Was this helpful?

  1. Cheat Sheets

Docker

Start with a Docker Compose file:docker-compose up

Start with a Docker Compose file and run as a background daemon:docker-compose up -d

Force recreate & rebuild a Docker Compose containers:docker-compose up --force-recreate --build

Stop services with Docker Compose:docker-compose stop

Stop and remove services with Docker Compose:docker-compose down

Connect to container shell:docker exec -it CONTAINER_NAME_HERE bash

Build Docker Compose project:docker-compose build

Stop containers and removes volumes:docker-compose down -v

See Docker processes:docker ps

See Docker stats (CPU, Memory, Network):docker stats

View Docker Compose logs:docker-compose logs

Remove unused images:docker image prune

Remove stopped containers:docker container prune

Remove stopped containers older than a week: docker container prune --filter "until=168h"

Remove unused volumes:docker volume prune

Remove unused networks:docker network prune

Run all prunes:docker system prune

See all containers (even stopped containers):docker ps -a --no-trunc

Remove containers that haven't been used in weeks:docker ps -a | grep Exited | grep "weeks ago" | awk '{print $1}' | xargs docker rm

Remove container:docker rm CONTAINER_NAME

Remove image:docker rmi IMAGE_NAME

Dumping and restoring postgres databases in Docker

Backup local database: docker exec -t postgres_container_name pg_dump -d db_name -c -U postgres > dev_db.dump

Import to local postgres in docker: docker exec -i postgres_container_name pg_restore -U postgres -v -d db_name --clean < latest.dump

Documentation links:

PreviousApacheNextGatsby

Last updated 3 years ago

Was this helpful?

Official documentation
Docker Tips and Cheatsheet
Local WordPress dev with Docker
Persisting MySQL data with Docker