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

Last updated