Docker Cheat Sheet

ADVERTISEMENT

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
Mounting a volume on container start
Start an interactive container
Force rebuild of Docker image
$>
docker run -v myvol:/data
redis
$>
docker run -it
ubuntu
bash
$>
docker build --no-cache .
Destroy a volume
Start a container automatically removed on stop
Convert a container to image
$>
docker volume rm myvol
$>
docker commit
c7337
myimage
$>
docker run --rm
ubuntu
bash
List volumes
Remove all unused images
$>
docker volume ls
Export port from a container
$>
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
Debug
Restart a stopped container
$>
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
Connect a running container from a network
Show live logs of running daemon container
$>
docker network connect mynet
c7337
$>
docker logs -f
c7337
Add metadata to container
Disconnect container to a network
$>
docker run -d \
Show exposed ports of a container
$>
docker network disconnect mynet
c7337
label=traefik.backend=jenkins
jenkins
$>
docker port
c7337
Manage Containers
Legend
List running containers
Image name
$>
docker ps
Delete all stopped containers
redis, jenkins, nginx
$>
docker rm $(docker ps --filter status=exited -q)
List all containers ( running & stopped )
$>
docker ps -a
List all containers with a specific label
Container name or commit ID
$>
docker ps --filter label=traefik.backend
mydb
#name
Inspect containers metadatas
c7337
#commit id
$>
docker inspect
c7337
Query a specific metadata of a running container
$>
docker inspect -f '{{ .NetworkSettings.IPAddress }}'
c7337
List local available images
$>
docker images
Docker Logo from Docker Inc & @bloglaurel

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go