Cheatography
https://cheatography.com
A detailed cheatsheet on Docker
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Dockerfile
FROM <existing-image>
|
Specifies an existing image to build on top of |
|
Set the working directory inside the container for all subsequent commands in the Dockerfile |
COPY <source> <destination>
|
Takes files or folders from your build context on your machine and places them inside the image’s filesystem |
|
Prepare the environment once, so every container starts ready to go |
CMD ["exec", "arg1", "arg2"]
|
Define what the container actually does when launched |
|
Container and Image Management
|
Lists currently running containers. -n
Show last n
created containers -a
List all containers -n
Last n
containers -q
Only container IDs |
docker start <container_name_or_id>
|
Restart a stopped container |
docker stop <container_name_or_id>
|
Stop a container |
docker rm <container_name_or_id>
|
Remove a container |
|
List all images |
|
Remove an image |
|
Download an image from a registry |
|
docker build
|
Give your image a name |
|
Path to a specific Dockerfile. Need when your Dockerfile is not named "Dockerfile" or not in the current directory. |
|
Passes build-time variables (used with ARG
in Dockerfile) |
|
Forces all layers to rebuild. Good when debugging inconsistent builds |
|
Always pulls the latest version of the base image |
|
Specifies architecture (helpful for multi-arch builds, Apple Silicon, etc.) |
|
Outputs only the final image ID (surpresses verbose logs) |
Turns a directory (with a Dockerfile) into an image
|
|
docker run
|
Runs the container in the background |
|
Maps a container port to a host port |
|
Gives the container a specific name |
|
Real-time sharing of given directory between your computer and the container |
|
Automatically removes the container when it stops |
|
Used for interactive shells |
|
Pass given variables into into the container |
Starts a container from an image
|