2022-05-06
List of docker commands that I personally use frequently
Table of contents
Overview
Hello, I'm Yuichi Ishiyama, Web Engineer!
In this article, we have compiled a list of frequently used commands for Docker, which is arguably indispensable for web app development.
Please refer to it in case you forget!
Basic operation system (build, startup, shutdown, etc.)
Building a Docker image
Build a Docker image based on the Dockerfile
docker-compose build
# Build without cache
docker-compose build --no-cache
Launching Docker Containers
Launching Docker Containers (Run in the directory where docker-compose.yml is located)
docker-compose up
# When you want to run in the background
docker-compose up -d
Deleting Docker Containers
Deleting Docker Containers (Run in the directory where docker-compose.yml is located)
docker-compose down
Control
Connect to Docker containers
Connect to Docker containers (Run in the directory where docker-compose.yml is located)
docker exec -it [Container Name] bash
# docker-composeの場合
docker-compose exec [Container Name] bash
Command execution in a Docker container
Execute commands in a running container (Run in the directory where docker-compose.yml is located)
docker-compose exec [Container Name] [Command]
Checking
Confirmation of startup container
Check Docker containers
docker ps
# Check all containers, including those that are stopped
docker ps -a
Confirmation of Docker image
Display and check the list of Docker images
docker images -a
Log
Container Log Display
Check logs for specific containers (Run in the directory where docker-compose.yml is located)
docker-compose logs [Container Name]
Real-time display of logs
Real-time display of logs output to the server (Run in the directory where docker-compose.yml is located)
docker-compose logs -ft
Cleaning
Total container shutdown
Stop all running containers
docker stop $(docker ps -aq)
Delete all containers
Delete all containers being started and stopped
docker rm $(docker ps -aq)
Delete all images
Delete the Docker image
docker rmi $(docker images -q)
Delete all
Delete everything, including container images (Type "y" when prompted with a warning and confirmation)
docker system prune
Delete unused containers
Delete unused containers
docker container prune
Delete unused images
Delete unused images
docker image prune