Docker Cheat Sheet
A complete cheat sheet can be found here
Lifecycle
- docker create creates a container but does not start it.
- docker run creates and starts a container in one operation.
- docker rename allows the container to be renamed.
- docker rm deletes a container.
- docker update updates a container's resource limits.
If you want a transient container, docker run --rm
will remove the
container after it stops.
If you want to map a directory on the host to a docker container,
docker run -v $HOSTDIR:$DOCKERDIR
.
Starting and Stopping
- docker start starts a container so it is running.
- docker stop stops a running container.
- docker restart stops and starts a container.
- docker pause pauses a running container, "freezing" it in place.
- docker attach will connect to a running container.
Info
- docker ps shows running containers.
- docker logs gets logs from container. (You can use a custom log driver, but logs is only available for json-file and journald in 1.10)
- docker inspect looks at all the info on a container (including IP address).
- docker events gets events from container.
- docker port shows public facing port of container.
- docker top shows running processes in container.
- docker stats shows containers' resource usage statistics.
- docker diff shows changed files in the container's FS.
docker ps -a
shows running and stopped containers.
docker stats --all
shows a running list of containers.
Executing Commands
- docker exec to execute a command in container.
To enter a running container, attach a new shell process to a running
container called foo, use: docker exec -it foo /bin/bash
.
Images
- docker images shows all images.
- docker build creates image from Dockerfile.