IMHO, docker
lightweight virtualization is an incredible game-changer. It totally
sweeps the “DevOps” board and along with etcd and Kubernetes
pods, supports complex application chain orchestrations through
mapped ports. In this short post, I have summarized my investigations
into the Docker CLI.
Image Management
- build
<dockerfile> - create an image according to a
dockerfile instructions
- commit
<container> - create an image from a container
- create
- create a new container from an image
- images
- list locally downloaded images: repository
name and tag, id, creation date, size
- login/logout - connect to docker hub
- pull/push <image> - download / upload an image
from a repository
- rmi
<image> - remove a local image
- search
- look for an image in repository
- tag
- add a tag to an image
- import
/ export - serialize / deserialize image to/from tar
- save
/ load - serialize / deserialize image of a
running container to/from tar
- history
- show history of an image
- build
- build an image from filesystem
- diff
- examine differences between images
- rmi
- remove an image
Container Control
- attach
<container> - attach to a running container
- cap-add/drop - fine grain control of
privelleges whitelist
- run
<image> [command] - download an image and execute it,
with an optional linux command
- -t
- assign a pseudo-tty or terminal inside the
container
- -i
- interactive connection by grabbing
container STDIN
- -d
- run container as a daemon
- -P
- map any required ports
- -p
<in:out> - map a specific port number pair
- --name - give a container instance a name
- --link - establish a secure tunnel to another
named container, optionally specify an alias
- --rm
- remove
- -v
- add a volume to a container. postfix with
:ro to make it read only
- -volumes-from - share data in container chain
- -H
- run on an external socket instead of
unix:///var/run/docker.sock
- --ip-forward - enable ip forwarding
- --iptables - enable firewall tables
eg
sudo docker run -t -i ubuntu:14.10 /bin/bash
sudo docker run --name <image2> --link db:db <image1>
env
- exec
<container> <command> - run a command on a container
- kill
<container>
- restart
<container> - restart. specify container restart
policy: no / on-failure / always
- rm
<container> - remove a stopped container.
- -f
- stop before removing
- start
/ pause / unpause / stop <container> - start / gracefully
stop a container
- wait
- block until a container stops
Container Queries
- inspect
<container> - JSON query of container config &
runtime info
- logs
<container> - capture STDOUT from a container
- port
<container> <outport> - query corresponding
mapped inport
- ps
- query docker daemon for running container instances
- -l
- lists container Id, image, command, creation date,
status, ports, names
- -a
- stopped containers only
- top
<container> - see what processes are running on
a container
- events
- listen to events from a container
- cp
- copy files between container and host
Other
- info
- check your install
- version
- version info