Docker cheat sheet
Written on February 7, 2017
Tweet
Docker cheet sheet
Containers
docker createcreates a container but does not start it.docker renameallows the container to be renamed.docker runcreates and starts a container in one operation.docker rmdeletes a container.docker updateupdates a container’s resource limits.docker startstarts a container so it is running.docker stopstops a running container.docker restartstops and starts a container.docker pausepauses a running container, “freezing” it in place.docker unpausewill unpause a running container.docker waitblocks until running container stops.docker killsends a SIGKILL to a running container.docker attachwill connect to a running container.docker psshows running containers.docker logsgets logs from container. (You can use a custom log driver, but logs is only available for json-file and journald in 1.10).docker inspectlooks at all the info on a container (including IP address).docker eventsgets events from container.docker portshows public facing port of container.docker topshows running processes in container.docker statsshows containers’ resource usage statistics.docker diffshows changed files in the container’s FS.docker ps -ashows running and stopped containers.docker stats --allshows a running list of containers.
Images
docker imagesshows all images.docker importcreates an image from a tarball.docker buildcreates image from Dockerfile.docker commitcreates image from a container, pausing it temporarily if it is running.docker rmiremoves an image.docker loadloads an image from a tar archive as STDIN, including images and tags (as of 0.7).docker savesaves an image to a tar archive stream to STDOUT with all parent layers, tags & versions.docker historyshows history of image.docker tagtags an image to a name (local or registry).
Registry & Repository
docker loginto login to a registry.docker logoutto logout from a registry.docker searchsearches registry for image.docker pullpulls an image from registry to local machine.docker pushpushes an image to the registry from local machine.
Dockerfile
FROMSets the Base Image for subsequent instructions.MAINTAINERSet the Author field of the generated images..RUNexecute any commands in a new layer on top of the current image and commit the results.CMDprovide defaults for an executing container.EXPOSEinforms Docker that the container listens on the specified network ports at runtime. NOTE: does not actually make ports accessible.ENVsets environment variable.ADDcopies new files, directories or remote file to container. Invalidates caches. Avoid ADD and use COPY instead.COPYcopies new files or directories to container.ENTRYPOINTconfigures a container that will run as an executable.VOLUMEcreates a mount point for externally mounted volumes or other containers.USERsets the user name for following RUN / CMD / ENTRYPOINT commands.WORKDIRsets the working directory.ARGdefines a build-time variable.ONBUILDadds a trigger instruction when the image is used as the base for another build.STOPSIGNALsets the system call signal that will be sent to the container to exit.LABELapply key/value metadata to your images, containers, or daemons.
Volumnes
docker volume createdocker volume rmdocker volume lsdocker volume inspect
Prune (Docker 1.13)
docker system prunedocker volume prunedocker network prunedocker container prunedocker image prune