Docker Build Too Slow? 10 Ways to Speed It Up
A slow Docker build usually has one of a few causes: you are sending far more...
Cheat sheet
Docker and Docker Compose commands grouped by task. Type in the filter to find one, click to copy, or grab the printable PDF.
matching Press / to filter
docker images
List local images
docker pull <image>:<tag>
Download an image from a registry
docker build -t <name>:<tag> .
Build an image from the Dockerfile in this folder
docker build -f <Dockerfile> -t <name> .
Build using a Dockerfile with another name
docker build --no-cache -t <name> .
Build without using cached layers
docker tag <image> <user>/<repo>:<tag>
Give an image another name (e.g. before pushing)
docker push <user>/<repo>:<tag>
Upload an image to a registry
docker rmi <image>
Delete an image
docker history <image>
Show the layers of an image and their sizes
docker login
Sign in to Docker Hub (or docker login <registry>)
docker run <image>
Create and start a container
docker run -d --name <name> <image>
Run in the background with a name
docker run -it <image> sh
Run interactively with a shell
docker run --rm <image>
Delete the container when it stops
docker run -p 8080:80 <image>
Publish container port 80 on host port 8080
docker run -e KEY=value <image>
Set an environment variable
docker run --env-file .env <image>
Load environment variables from a file
docker run -v $(pwd):/app <image>
Mount the current folder into the container
docker run --restart unless-stopped <image>
Restart automatically unless stopped by you
docker ps
List running containers
docker ps -a
List all containers, including stopped ones
docker stop <container>
Stop a container gracefully
docker start <container>
Start a stopped container
docker restart <container>
Restart a container
docker kill <container>
Stop a container immediately
docker rm <container>
Delete a stopped container
docker rm -f <container>
Stop and delete a running container
docker rename <old> <new>
Rename a container
docker logs <container>
Show a container's output
docker logs -f --tail 100 <container>
Follow the log, starting with the last 100 lines
docker exec -it <container> sh
Open a shell in a running container (bash if available)
docker exec <container> <command>
Run one command in a running container
docker inspect <container>
Full configuration and state as JSON
docker stats
Live CPU, memory and network use per container
docker top <container>
Processes running inside a container
docker cp <container>:<path> <local-path>
Copy a file out of a container
docker cp <local-path> <container>:<path>
Copy a file into a container
docker port <container>
Show the published ports
docker volume ls
List volumes
docker volume create <name>
Create a named volume
docker run -v <volume>:/data <image>
Mount a named volume (data survives the container)
docker volume inspect <name>
Show where a volume is stored
docker volume rm <name>
Delete a volume and its data
docker network ls
List networks
docker network create <name>
Create a network
docker run --network <name> <image>
Start a container on a network (containers reach each other by name)
docker network connect <network> <container>
Attach a running container to a network
docker network inspect <name>
Show a network and its containers
docker network rm <name>
Delete a network
docker compose up -d
Start all services in the background
docker compose up -d --build
Rebuild images, then start
docker compose down
Stop and remove the services and their network
docker compose down -v
Also delete the volumes (data is lost)
docker compose ps
List the services and their state
docker compose logs -f <service>
Follow one service's log
docker compose exec <service> sh
Open a shell in a running service
docker compose run --rm <service> <command>
Run a one-off command in a new container
docker compose restart <service>
Restart one service
docker compose pull
Download newer images for the services
docker compose config
Show the final configuration after merging files and variables
FROM php:8.3-fpm-alpine
Base image to start from
WORKDIR /app
Folder for the following instructions
COPY . .
Copy files from the build context into the image
RUN apk add --no-cache git
Run a command while building (one layer)
ENV APP_ENV=production
Set an environment variable
ARG VERSION=1.0
Build-time variable (docker build --build-arg VERSION=2.0)
EXPOSE 8080
Document the port the app listens on
CMD ["php-fpm"]
Default command when the container starts
ENTRYPOINT ["docker-entrypoint.sh"]
Fixed executable; CMD becomes its arguments
HEALTHCHECK CMD curl -f http://localhost/ || exit 1
How Docker checks the container is healthy
docker system df
Disk space used by images, containers, volumes and cache
docker container prune
Delete all stopped containers
docker image prune
Delete dangling (untagged) images
docker image prune -a
Delete all images not used by a container
docker volume prune
Delete unused volumes (data is lost)
docker builder prune
Delete the build cache
docker system prune
Delete stopped containers, unused networks, dangling images and build cache
docker system prune -a --volumes
Delete everything unused, volumes included (careful)
All 78 commands on a printable A4 PDF. Free for newsletter subscribers.
An image is a read-only template (the app and everything it needs). A container is a running instance of an image; you can start many containers from one image.
ENTRYPOINT sets the executable that always runs; CMD supplies default arguments (or the default command when there is no ENTRYPOINT). Arguments passed to docker run replace CMD, not ENTRYPOINT.
Check usage with docker system df, then run docker system prune. Add -a to also remove unused images and --volumes to remove unused volumes, but volumes may hold database data.
docker compose (with a space) is Compose v2, built into the Docker CLI. The old docker-compose (with a hyphen) is v1 and no longer updated; the commands are otherwise the same.
A slow Docker build usually has one of a few causes: you are sending far more...
People ask this as if they were rivals, and they are not. Docker packages your application...
You dispatch a job, nothing happens, and there is no error. Or the job ran once,...
We use cookies to improve your experience and analyze traffic. By continuing, you agree to our Privacy Policy.