Docker Commands Cheat Sheet
This cheat sheet is a reminder for myself, which might come in handy in the daily life of a PHP and Node.js backend developer.
Container Management
- List running containers:
docker ps
- List all containers (including stopped):
docker ps -a
- Create a container from an image without starting it:
docker create
- Rename a container:
docker rename [container] [new-name]
- Remove a container:
docker rm [container]
, use-f
to force remove a running container. - View logs for a container:
docker logs [container]
, use-f --until=[interval]
to display logs up to a certain point in time. - Update a container’s configuration:
docker update [container]
- Show container’s port mappings:
docker port [container]
- Show running processes in a container:
docker top [container]
- Show live resource usage statistics of a container:
docker stats [container]
- Show changes to files or directories on a container’s filesystem:
docker diff [container]
- Copy files to/from a container:
docker cp [file-path] CONTAINER:[path]
Networking
- View available networks:
docker network ls
- Remove a network:
docker network rm [network]
- Connect a container to a network:
docker network connect [network] [container]
- Disconnect a container from a network:
docker network disconnect [network] [container]
- Show detailed information about a network:
docker network inspect [network]
Image Management
- Create an image from a Dockerfile:
docker build [dockerfile-path]
, use-t [name]:[tag]
to tag it. - Pull an image from a registry:
docker pull
- Push an image to a registry:
docker push
- Save changes in a container as a new image:
docker commit [container] [new-image]
- View all locally stored top-level images:
docker images
- Remove an image:
docker rmi
- Show history of an image:
docker history
- Save an image to a tar archive file:
docker save > [tar-file]
- Remove unused images:
docker image prune
The docker commands cheat sheet: #CheatSheetDocker