Cheatsheet
Check Version
docker versionshows which version of docker you have running.
Containers
Lifecycle
β
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.
Starting and Stopping
β
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.
β
CPU Constraints You can limit CPU, either using a percentage of all CPUs, or by using specific cores.For example, you can tell the cpu-shares setting.
The setting is a bit strange -- 1024 means 100% of the CPU, so if you want the container to take 50% of all CPU cores, you should specify 512:docker run -it -c 512 agileek/cpuset-test
You can also only use some CPU cores using cpuset-cpus:docker run -it --cpuset-cpus=0,4,6 agileek/cpuset-test
Note that Docker can still see all of the CPUs inside the container -- it just isn't using all of them.
Memory Constraints: You can also set memory constraints on Docker:docker run -it -m 300M ubuntu:14.04 /bin/bash
Info
β
docker psshows running containers.β
docker logsgets logs from container.β
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.
Import / Export
β
docker cpcopies files or folders between a container and the local filesystem.β
docker exportturns container filesystem into tarball archive stream to STDOUT.
Import/Export container
Import a container as an image from file:cat my_container.tar.gz | docker import - my_image:my_tagExport an existing container:docker export my_container | gzip > my_container.tar.gz
Executing Commands
β
docker execto execute a command in container.
Images
Lifecycle
β
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 (as of 0.7).
Info
β
docker historyshows history of image.β
docker tagtags an image to a name (local or registry).
Load/Save image
Load an image from file:
Save an existing image:
Dockerfile
Instructions
β.dockerignoreβ
βFROM Sets the Base Image for subsequent instructions.
βMAINTAINER (deprecated - use LABEL instead) Set the Author field of the generated images.
βRUN execute any commands in a new layer on top of the current image and commit the results.
βCMD provide defaults for an executing container.
βEXPOSE informs Docker that the container listens on the specified network ports at runtime. NOTE: does not actually make ports accessible.
βENV sets environment variable.
βADD copies new files, directories or remote file to container. Invalidates caches. Avoid
ADDand useCOPYinstead.βCOPY copies new files or directories to container. By default this copies as root regardless of the USER/WORKDIR settings. Use
--chown=<user>:<group>to give ownership to another user/group. (Same forADD.)βENTRYPOINT configures a container that will run as an executable.
βVOLUME creates a mount point for externally mounted volumes or other containers.
βUSER sets the user name for following RUN / CMD / ENTRYPOINT commands.
βWORKDIR sets the working directory.
βARG defines a build-time variable.
βONBUILD adds a trigger instruction when the image is used as the base for another build.
βSTOPSIGNAL sets the system call signal that will be sent to the container to exit.
βLABEL apply key/value metadata to your images, containers, or daemons.
βSHELL override default shell is used by docker to run commands.
βHEALTHCHECK tells docker how to test a container to check that it is still working.
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.
Volumes
Lifecycle
β
docker volume createββ
docker volume rmβ
Info
β
docker volume lsββ
docker volume inspectβ
Networks
Lifecycle
β
docker network createNAME Create a new network (default type: bridge).β
docker network rmNAME Remove one or more networks by name or identifier. No containers can be connected to the network when deleting it.
Info
β
docker network lsList networksβ
docker network inspectNAME Display detailed information on one or more networks.
Connection
β
docker network connectNETWORK CONTAINER Connect a container to a networkβ
docker network disconnectNETWORK CONTAINER Disconnect a container from a network.
βhttps://github.com/wsargent/docker-cheat-sheet#dockerfile
Last updated