You are on page 1of 2

1.

Containers Give access to all devices:


A lightweight virtual OS that run processes in docker run -it --privileged -v /dev/bus/us-
full isolation. b:/dev/bus/usb debian bash
1.1 Lifecycle
docker create creates a container but does 1.6 Info
not start it. docker ps shows running containers.
docker rename allows the container to be docker logs gets logs from container. (You can
renamed.
docker run creates and starts a container in use a custom log driver, but logs is only availa-
one operation. ble for json-fileand journald in 1.10).
docker rm deletes a container. docker inspect looks at all the info on a con-
docker update updates a container's resource limits.
docker run --rm : remove the container after it stops. tainer (including IP address).
docker run -v $HOSTDIR:$DOCKERDIR: map docker events gets events from container.
the directory ($HOSTDIR) on the host to a
docker container ($DOCKERDIR). docker port shows public facing port of con-
docker rm –v: remove the volumes associat- tainer.
ed with the container. docker top shows running processes in con-
docker run --log-driver=syslog : run docker
with a custom log driver. tainer.
docker stats shows containers' resource usage
1.2 Starting and Stopping
docker start starts a container so it is running. statistics.
docker stop stops a running container. docker diff shows changed files in the contain-
docker restart stops and starts a container. er's FS.
docker pause pauses a running container,
"freezing" it in place. docker ps –ashows running and stopped con-
docker unpause will unpause a running tainers
container. 1.7 Import / Export
docker wait blocks until running container
stops. docker cp copies files or folders between a
docker kill sends a SIGKILL to a running con- container and the local filesystem.
tainer. docker export turns container filesystem into
docker attach will connect to a running con-
tainer. tarball archive stream to STDOUT.
1.3 CPU Constraints 1.8 Executing Commands
CPU can be limited either using a percentage docker exec to execute a command in container.
over all CPUs, or by using specific cores.
-c or cpu-shares: 1024 means 100% of the 2. Images
CPU, so if we want the container to take 50% A template or blueprint for docker containers.
of all CPU cores, we should specify 512 for
2.1 Lifecycle
instance, docker run -ti --c 512 …cpuset-cpus
: use only some CPU cores, for instance, docker images shows all images.
docker run -ti --cpuset-cpus=0,4,6 … docker import creates an image from a tarball.
1.4 Memory Constraints docker build creates image from Dockerfile.
Memory can be limited using –m flag, for docker commit creates image from a contain-
instance, docker run -it -m 300M ubun- er, pausing it temporarily if it is running.
tu:14.04 /bin/bash
docker rmi removes an image.
1.5 Capabilities
docker load loads an image from a tar archive
cap-add and cap-drop: Add or drop linux capabilities.
as STDIN, including images and tags (as of 0.7).
Mount a FUSE based filesystem:
docker run --rm -it --cap-add SYS_ADMIN docker save saves an image to a tar archive
--device /dev/fuse sshfs stream to STDOUT with all parent layers, tags
Give access to a single device: & versions (as of 0.7).
docker run -it --device=/dev/ttyUSB0 debian bash

Linoxide - Linux Trends


2.2. Info 5. Volumes
docker history shows history of image. Docker volumes are free-floating filesystems. They
docker tag tags an image to a name (local or don't have to be connected to a particular contain-
registry). er. You should use volumes mounted from
2.3. Cleaning up data-only containers for portability.
5.1. Lifecycle
docker rmi remove specific images. docker volume create
docker-gc a toolto clean up images that are docker volume rm
no longer used by any containers in a safe 5.2. Info
manner. docker volume ls
docker volume inspect
2.4. Load/Save image
docker load < my_image.tar.gz load an image 6. Exposing ports
from file docker run -p 127.0.0.1:$HOSTPORT:$CONTAINER-
docker save my_image:my_tag | gzip > PORT --name CONTAINER -t docker_image map-
my_image.tar.gz save an existing image ping the container port to the host port using –p
EXPOSE <CONTAINERPORT>expose port CONTAIN-
2.5. Import/Export container
ERPORT at runtime (see dockerfile)
cat my_container.tar.gz | docker import - docker port CONTAINER $CONTAINERPORT check
my_image:my_tag import a container as an the mapped port
image from file 7. Tips
docker export my_container | gzip > my_con- 7.1. Get IP address
tainer.tar.gz export an existing container docker inspect some_docker_id | grep IPAddress
| cut -d '"' -f 4
3. Networks or install jq:
A small def goes here docker inspect some_docker_id | jq -r '.[0].Net-
workSettings.IPAddress'
3.1. Lifecycle or using a go template:
docker network create docker inspect -f '{{ .NetworkSettings.IPAddress }}'
<container_name>
docker network rm 7.2. Get port mapping
3.2. Info docker inspect -f '{{range $p, $conf := .Net-
docker network ls workSettings.Ports}} {{$p}} -> {{(index $conf
docker network inspect 0).HostPort}} {{end}}' <containername>
3.3. Connection 7.3. Find containers by regular expression
docker network connect for i in $(docker ps -a | grep "REGEXP_PAT-
docker network disconnect TERN" | cut -f1 -d" "); do echo $i; done
7.4. Get Environment Settings
4. Registry & Repository
docker run --rm ubuntu env
A repository is a hosted collection of tagged 7.5. Kill running containers
images that together create the file system for a docker kill $(docker ps -q)
container. 7.6. Delete old containers
A registry is a host -- a server that stores reposito- docker ps -a | grep 'weeks ago' | awk '{print
ries and provides an HTTP API for managing the
uploading and downloading of repositories. $1}' | xargs docker rm
Docker.com hosts its own index to a central regis- 7.7. Delete stopped containers
try which contains a large number of repositories. docker rm -v $(docker ps -a -q -f status=exited)
docker login to login to a registry. 7.8. Delete dangling images
docker logout to logout from a registry. docker rmi $(docker images -q -f dan-
docker search searches registry for image. gling=true)
7.9. Delete all images
docker pull pulls an image from registry to
docker rmi $(docker images -q)
local machine.
7.10. Delete dangling volumes
docker push pushes an image to the registry
from local machine. docker volume rm $(docker volume ls -q -f
dangling=true)
Linoxide - Linux Trends

You might also like