You are on page 1of 1

Docker Cheat Sheet dockerlux.github.

io
@gcuisinier
General Usage Build Images Volumes
Start a container in background Build an image from Dockerfile in current directory Create a local volume
$> docker run -d jenkins $> docker build --tag myimage . $> docker volume create --name myvol
Start an interactive container Force rebuild of Docker image Mounting a volume on container start
$> docker run -it ubuntu bash $> docker build --no-cache . $> docker run -v myvol:/data redis
Destroy a volume
Start a container automatically removed on stop Convert a container to image
$> docker volume rm myvol
$> docker run --rm ubuntu bash $> docker commit c7337 myimage
List volumes
Export port from a container Remove all unused images $> docker volume ls
$> docker run -p 80:80 -d nginx $> docker rmi $(docker images \
-q -f "dangling=true"
Start a named container
$> docker run --name mydb redis
Create a local network
Restart a stopped container Debug $> docker network create mynet
$> docker start mydb
Run another process in running container Attach a container to a network on start
Stop a container $> docker exec -it c7337 bash $> docker run -d --net mynet redis
$> docker stop mydb
Show live logs of running daemon container Connect a running container from a network
Add metadata to container $> docker logs -f c7337 $> docker network connect mynet c7337
$> docker run -d \ Disconnect container to a network
Show exposed ports of a container
label=traek.backend=jenkins jenkins $> docker network disconnect mynet c7337
$> docker port c7337

Manage Containers Legend


List running containers
Image name
$> docker ps Delete all stopped containers redis, jenkins, nginx
List all containers ( running & stopped ) $> docker rm $(docker ps --lter status=exited -q)
$> docker ps -a List all containers with a specific label Container name or commit ID
Inspect containers metadatas $> docker ps --lter label=traek.backend mydb #name
$> docker inspect c7337 c7337 #commit id
Query a specific metadata of a running container
List local available images $> docker inspect -f '{{ .NetworkSettings.IPAddress }}' c7337
$> docker images

Docker Logo from Docker Inc & @bloglaurel

You might also like