NOTE: This used to be a gist that continually expanded. It's now a github project because it's considerably easier for other people to edit, fix and expand on Docker using Github. Just click README.md, and then on the "writing pen" icon on the right to edit.
- Why
- Prerequisites
- Installation
- Containers
- Images
- Registry and Repository
- Dockerfile
- Layers
- Links
- Volumes
- Exposing Ports
- Machine, Swarm and Compose
- Best Practices
- Tips
- Tools
"With Docker, developers can build any app in any language using any toolchain. “Dockerized” apps are completely portable and can run anywhere - colleagues’ OS X and Windows laptops, QA servers running Ubuntu in the cloud, and production data center VMs running Red Hat.
Developers can get going quickly by starting with one of the 13,000+ apps available on Docker Hub. Docker manages and tracks changes and dependencies, making it easier for sysadmins to understand how the apps that developers build work. And with Docker Hub, developers can automate their build pipeline and share artifacts with collaborators through public or private repositories.
Docker helps developers build and ship higher-quality applications, faster." -- What is Docker
I use Oh My Zsh with the Docker plugin for autocompletion of docker commands. YMMV.
The 3.10.x kernel is the minimum requirement for Docker.
Use Homebrew.
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
Installation instructions are available. Docker has recognized that installation / deployment is a PITA, and Docker Machine aka bug 8681 deals with this specifically.
Quick and easy install script provided by Docker:
curl -sSL https://get.docker.com/ | sh
If you're not willing to run a random shell script, please see the installation instructions for your distribution.
Download Docker for OSX from the Github Releases page.
The canonical way to use Docker is with the aid of the boot2docker VM. However, using the out of the box boot2docker doesn't give me control over my Vagrant instances (especially the lack of port forwarding). So here's how to use boot2docker from a Vagrant instance.
We use the YungSang modified boot2docker instance from the Vagrant Cloud:
mkdir ~/boot2docker
cd ~/boot2docker
vagrant init yungsang/boot2docker
vagrant up
export DOCKER_HOST=tcp://localhost:2375
docker version
NOTE: the YungSang boot2docker opens up port forwarding to the network, so is not safe on public wifi. You can make a good argument that docker without TLS is fundamentally unsafe. I only do it because I have Hands Off installed to limit external network access.
Then start up a container:
docker run -i -t ubuntu /bin/bash
That's it, you have a running Docker container.
Your basic isolated Docker process. Containers are to Virtual Machines as threads are to processes. Or you can think of them as chroots on steroids.
docker create
creates a container but does not start it.docker run
creates and starts a container in one operation.docker stop
stops it.docker start
will start it again.docker restart
restarts a container.docker rm
deletes a container.docker kill
sends a SIGKILL to a container.docker attach
will connect to a running container.docker wait
blocks until container stops.
If you want to run and then interact with a container, docker start
, then spawn a shell as described in Executing Commands.
If you want a transient container, docker run --rm
will remove the container after it stops.
If you want to remove also the volumes associated with the container, the deletion of the container must include the -v switch like in docker --rm -v
.
If you want to poke around in an image, docker run -t -i <myimage> <myshell>
to open a tty.
If you want to poke around in a running container, docker exec -t -i <mycontainer> <myshell>
to open a tty.
If you want to map a directory on the host to a docker container, docker run -v $HOSTDIR:$DOCKERDIR
. Also see Volumes.
If you want to integrate a container with a host process manager, start the daemon with -r=false
then use docker start -a
.
If you want to expose container ports through the host, see the exposing ports section.
Restart policies on crashed docker instances are covered here.
docker ps
shows running containers.docker logs
gets logs from container.docker inspect
looks at all the info on a container (including IP address).docker events
gets events from container.docker port
shows public facing port of container.docker top
shows running processes in container.docker stats
shows containers' resource usage statistics.docker diff
shows changed files in the container's FS.
docker ps -a
shows running and stopped containers.
There doesn't seem to be a way to use docker directly to import files into a container's filesystem. The closest thing is to mount a host file or directory as a data volume and copy it from inside the container.
docker cp
copies files or folders out of a container's filesystem.docker export
turns container filesystem into tarball archive stream to STDOUT.