Be smart. Think open source.
isolated user-space processes
a.k.a. OS-level virtualization
Which solutions are available?
Check your docker version
docker version
Check the available docker options
docker
Your first hello-world container
docker run hello-world
This pulls the image hello-world:latest if it isn't found locally
echo "hello world"
docker run debian echo "hello world"
interactive shell
docker run -it debian bash
# cat /etc/debian_version
Search image foo on Docker Hub
docker search foo
Download image bar
docker pull bar
List local images
docker images
Delete image baz locally
docker rmi baz
Download image foo with tag bar
docker pull foo:bar
Delete image foo with tag bar locally
docker rmi foo:bar
Rename/retag an image
docker tag example example:stable
Download the image bar from the repository foo
docker pull foo/bar
Pull an image from the registry example.com
docker pull example.com/foo/bar
Push an image to the registry example.com
docker push example.com/foo/bar
Start a container from the image foo
docker run foo
Start a container in the background
docker run -d foo
Show running containers
docker ps
Show logs from a container
docker logs -f $CONTAINER_ID
Show processes running in a container
docker top $CONTAINER_ID
Stop a running container
docker stop $CONTAINER_ID
Kill a running container
docker kill $CONTAINER_ID
Delete a container
docker rm $CONTAINER_ID
Expose a container port on the host
docker run -p 8080:80 nginx
Expose all configured ports on random ports on the host
docker run -P nginx
Show exposed ports of a container
docker port $CONTAINER_ID
Run a interactive shell in a container
docker run -it foo /bin/bash
Start a interactive shell in a running container
docker exec -it $CONTAINER_ID /bin/bash
To override the automatically generated names you can specify a name on the CLI
docker run --name nginx_proxy nginx
The option --rm
deletes the container on exit
docker run --rm centos yum list installed