DOCKER(1)

NAME
docker - Docker Documentation

This documentation has the following resources:

CONCEPTS

Contents:

  Standard Containers

  What is a Standard Container?

Docker defines a unit of software delivery called a Standard Container. The goal of a Standard Container is to encapsulate a software component and all its dependencies in a format that is self-describing and portable, so that any compliant runtime can run it without extra dependency, regardless of the underlying machine and the contents of the container.

The spec for Standard Containers is currently work in progress, but it is very straightforward. It mostly defines 1) an image format, 2) a set of standard operations, and 3) an execution environment.

A great analogy for this is the shipping container. Just like Standard Containers are a fundamental unit of software delivery, shipping containers (http://bricks.argz.com/ins/7823-1/12) are a fundamental unit of physical delivery.

  Standard operations

Just like shipping containers, Standard Containers define a set of STANDARD OPERATIONS. Shipping containers can be lifted, stacked, locked, loaded, unloaded and labelled. Similarly, standard containers can be started, stopped, copied, snapshotted, downloaded, uploaded and tagged.

  Content-agnostic

Just like shipping containers, Standard Containers are CONTENT-AGNOSTIC: all standard operations have the same effect regardless of the contents. A shipping container will be stacked in exactly the same way whether it contains Vietnamese powder coffee or spare Maserati parts. Similarly, Standard Containers are started or uploaded in the same way whether they contain a postgres database, a php application with its dependencies and application server, or Java build artifacts.

  Infrastructure-agnostic

Both types of containers are INFRASTRUCTURE-AGNOSTIC: they can be transported to thousands of facilities around the world, and manipulated by a wide variety of equipment. A shipping container can be packed in a factory in Ukraine, transported by truck to the nearest routing center, stacked onto a train, loaded into a German boat by an Australian-built crane, stored in a warehouse at a US facility, etc. Similarly, a standard container can be bundled on my laptop, uploaded to S3, downloaded, run and snapshotted by a build server at Equinix in Virginia, uploaded to 10 staging servers in a home-made Openstack cluster, then sent to 30 production instances across 3 EC2 regions.

  Designed for automation

Because they offer the same standard operations regardless of content and infrastructure, Standard Containers, just like their physical counterpart, are extremely well-suited for automation. In fact, you could say automation is their secret weapon.

Many things that once required time-consuming and error-prone human effort can now be programmed. Before shipping containers, a bag of powder coffee was hauled, dragged, dropped, rolled and stacked by 10 different people in 10 different locations by the time it reached its destination. 1 out of 50 disappeared. 1 out of 20 was damaged. The process was slow, inefficient and cost a fortune - and was entirely different depending on the facility and the type of goods.

Similarly, before Standard Containers, by the time a software component ran in production, it had been individually built, configured, bundled, documented, patched, vendored, templated, tweaked and instrumented by 10 different people on 10 different computers. Builds failed, libraries conflicted, mirrors crashed, post-it notes were lost, logs were misplaced, cluster updates were half-broken. The process was slow, inefficient and cost a fortune - and was entirely different depending on the language and infrastructure provider.

  Industrial-grade delivery

There are 17 million shipping containers in existence, packed with every physical good imaginable. Every single one of them can be loaded on the same boats, by the same cranes, in the same facilities, and sent anywhere in the World with incredible efficiency. It is embarrassing to think that a 30 ton shipment of coffee can safely travel half-way across the World in less time than it takes a software team to deliver its code from one datacenter to another sitting 10 miles away.

With Standard Containers we can put an end to that embarrassment, by making INDUSTRIAL-GRADE DELIVERY of software a reality.

  Standard Container Specification

(TODO)

  Image format

  Standard operations

•   Copy

•   Run

•   Stop

•   Wait

•   Commit

•   Attach standard streams

•   List filesystem changes

•

  Execution environment

  Root filesystem

  Environment variables

  Process arguments

  Networking

  Process namespacing

  Resource limits

  Process monitoring

  Logging

  Signals

  Pseudo-terminal allocation

  Security

INSTALLATION

Contents:

  Ubuntu Linux
Please note this project is currently under heavy development. It should not be used in production.

Installing on Ubuntu 12.04 and 12.10

Right now, the officially supported distributions are:

Ubuntu 12.04 (precise LTS) Ubuntu 12.10 (quantal) Docker probably works on other distributions featuring a recent kernel, the AUFS patch, and up-to-date lxc. However this has not been tested.

  Install dependencies:

sudo apt-get install lxc wget bsdtar curl
sudo apt-get install linux-image-extra-`uname -r`

The linux-image-extra package is needed on standard Ubuntu EC2 AMIs in order to install the aufs kernel module.

Install the latest docker binary:

wget http://get.docker.io/builds/$(uname -s)/$(uname -m)/docker-master.tgz
tar -xf docker-master.tgz

Run your first container!

cd docker-master

sudo ./docker run -i -t base /bin/bash

Consider adding docker to your PATH for simplicity.

Continue with the hello_world example.

  Mac OS X and other linux
Please note this is a community contributed installation path. The only 'official' installation is using the ubuntu_linux installation path. This version may be out of date because it depends on some binaries to be updated and published

  Requirements

We currently rely on some Ubuntu-linux specific packages, this will change in the future, but for now we provide a streamlined path to install Virtualbox with a Ubuntu 12.10 image using Vagrant.

1.  Install virtualbox from https://www.virtualbox.org/ (or use your package manager)

2.  Install vagrant from http://www.vagrantup.com/ (or use your package manager)

3.  Install git if you had not installed it before, check if it is installed by running git in a terminal window

    We recommend having at least about 2Gb of free disk space and 2Gb RAM (or more).

  Installation

1.  Fetch the docker sources

    git clone https://github.com/dotcloud/docker.git

2.  Run vagrant from the sources directory

    vagrant up

    Vagrant will:

•   Download the Quantal64 base ubuntu virtual machine image from get.docker.io/

•   Boot this image in virtualbox

    Then it will use Puppet to perform an initial setup in this machine:

•   Download & untar the most recent docker binary tarball to vagrant homedir.

•   Debootstrap to /var/lib/docker/images/ubuntu.

•   Install & run dockerd as service.

•   Put docker in /usr/local/bin.

•   Put latest Go toolchain in /usr/local/go.

    You now have a Ubuntu Virtual Machine running with docker pre-installed.

    To access the VM and use Docker, Run vagrant ssh from the same directory as where you ran vagrant up. Vagrant will make sure to connect you to the correct VM.

    vagrant ssh

    Now you are in the VM, run docker

    docker

    Continue with the hello_world example.

  Windows
Please note this is a community contributed installation path. The only 'official' installation is using the ubuntu_linux installation path. This version may be out of date because it depends on some binaries to be updated and published

  Requirements

1.  Install virtualbox from https://www.virtualbox.org - or follow this tutorial

2.  Install vagrant from http://www.vagrantup.com - or follow this tutorial

3.  Install git with ssh from http://git-scm.com/downloads - or follow this tutorial

    We recommend having at least 2Gb of free disk space and 2Gb of RAM (or more).

  Opening a command prompt

First open a cmd prompt. Press Windows key and then press “R” key. This will open the RUN dialog box for you. Type “cmd” and press Enter. Or you can click on Start, type “cmd” in the “Search programs and files” field, and click on cmd.exe. [image: Git install] [image]

This should open a cmd prompt window. [image: run docker] [image]

Alternatively, you can also use a Cygwin terminal, or Git Bash (or any other command line program you are usually using). The next steps would be the same.

  Launch an Ubuntu virtual server

Let’s download and run an Ubuntu image with docker binaries already installed.

git clone https://github.com/dotcloud/docker.git
cd docker
vagrant up
[image: run docker] [image]

Congratulations! You are running an Ubuntu server with docker installed on it. You do not see it though, because it is running in the background.

  Log onto your Ubuntu server

Let’s log into your Ubuntu server now. To do so you have two choices:

•   Use Vagrant on Windows command prompt OR

•   Use SSH

  Using Vagrant on Windows Command Prompt

Run the following command

vagrant ssh

You may see an error message starting with “ssh executable not found”. In this case it means that you do not have SSH in your PATH. If you do not have SSH in your PATH you can set it up with the “set” command. For instance, if your ssh.exe is in the folder named “C:Program Files (x86)Gitbin”, then you can run the following command:

set PATH=%PATH%;C:\Program Files (x86)\Git\bin
[image: run docker] [image]

  Using SSH

First step is to get the IP and port of your Ubuntu server. Simply run:

vagrant ssh-config

You should see an output with HostName and Port information. In this example, HostName is 127.0.0.1 and port is 2222. And the User is “vagrant”. The password is not shown, but it is also “vagrant”. [image: run docker] [image]

You can now use this information for connecting via SSH to your server. To do so you can:

•   Use putty.exe OR

•   Use SSH from a terminal

  Use putty.exe

You can download putty.exe from this page http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html Launch putty.exe and simply enter the information you got from last step. [image: run docker] [image]

Open, and enter user = vagrant and password = vagrant. [image: run docker] [image]

  SSH from a terminal

You can also run this command on your favorite terminal (windows prompt, cygwin, git-bash, …). Make sure to adapt the IP and port from what you got from the vagrant ssh-config command.

ssh vagrant@127.0.0.1 –p 2222

Enter user = vagrant and password = vagrant. [image: run docker] [image]

Congratulations, you are now logged onto your Ubuntu Server, running on top of your Windows machine !

  Running Docker

First you have to be root in order to run docker. Simply run the following command:

sudo su

You are now ready for the docker’s “hello world” example. Run

docker run -a busybox echo hello world
[image: run docker] [image]

All done!

Now you can continue with the hello_world example.

  Amazon EC2
Please note this is a community contributed installation path. The only 'official' installation is using the ubuntu_linux installation path. This version may be out of date because it depends on some binaries to be updated and published

  Installation

Docker can now be installed on Amazon EC2 with a single vagrant command. Vagrant 1.1 or higher is required.

1.  Install vagrant from http://www.vagrantup.com/ (or use your package manager)

2.  Install the vagrant aws plugin

    vagrant plugin install vagrant-aws

3.  Get the docker sources, this will give you the latest Vagrantfile and puppet manifests.

    git clone https://github.com/dotcloud/docker.git

4.  Check your AWS environment.

    Create a keypair specifically for EC2, give it a name and save it to your disk. I usually store these in my ~/.ssh/ folder.

    Check that your default security group has an inbound rule to accept SSH (port 22) connections.

5.  Inform Vagrant of your settings

    Vagrant will read your access credentials from your environment, so we need to set them there first. Make sure you have everything on amazon aws setup so you can (manually) deploy a new image to EC2.

    export AWS_ACCESS_KEY_ID=xxx
    export AWS_SECRET_ACCESS_KEY=xxx
    export AWS_KEYPAIR_NAME=xxx
    export AWS_SSH_PRIVKEY=xxx

    The environment variables are:

•   AWS_ACCESS_KEY_ID - The API key used to make requests to AWS

•   AWS_SECRET_ACCESS_KEY - The secret key to make AWS API requests

•   AWS_KEYPAIR_NAME - The name of the keypair used for this EC2 instance

•   AWS_SSH_PRIVKEY - The path to the private key for the named keypair, for example ~/.ssh/docker.pem

    You can check if they are set correctly by doing something like

    echo $AWS_ACCESS_KEY_ID

6.  Do the magic!

    vagrant up --provider=aws

    If it stalls indefinitely on [default] Waiting for SSH to become available..., Double check your default security zone on AWS includes rights to SSH (port 22) to your container.

    If you have an advanced AWS setup, you might want to have a look at the https://github.com/mitchellh/vagrant-aws

7.  Connect to your machine

    vagrant ssh

8.  Your first command

    Now you are in the VM, run docker

    docker

    Continue with the hello_world example.

EXAMPLES

Contents:

  Hello World

This is the most basic example available for using docker

This example assumes you have Docker installed.

Download the base container

# Download a base image
docker pull base

The base image is a minimal ubuntu based container, alternatively you can select busybox, a bare minimal linux system. The images are retrieved from the docker repository.

#run a simple echo command, that will echo hello world back to the console over standard out.
docker run base /bin/echo hello world

Explanation:

•   "docker run" run a command in a new container

•   "base" is the image we want to run the command inside of.

•   "/bin/echo" is the command we want to run in the container

•   "hello world" is the input for the echo command

    Video:

    See the example in action

    Continue to the hello_world_daemon example.

  Hello World Daemon

The most boring daemon ever written.

This example assumes you have Docker installed and with the base image already imported docker pull base. We will use the base image to run a simple hello world daemon that will just print hello world to standard out every second. It will continue to do this until we stop it.

Steps:

$ CONTAINER_ID=$(docker run -d base /bin/sh -c "while true; do echo hello world; sleep 1; done")

We are going to run a simple hello world daemon in a new container made from the busybox daemon.

•   "docker run -d " run a command in a new container. We pass "-d" so it runs as a daemon.

•   "base" is the image we want to run the command inside of.

•   "/bin/sh -c" is the command we want to run in the container

•   "while true; do echo hello world; sleep 1; done" is the mini script we want to run, that will just print hello world once a second until we stop it.

•   $CONTAINER_ID the output of the run command will return a container id, we can use in future commands to see what is going on with this process.

    $ docker logs $CONTAINER_ID

    Check the logs make sure it is working correctly.

•   "docker logs" This will return the logs for a container

•   $CONTAINER_ID The Id of the container we want the logs for.

    docker attach $CONTAINER_ID

    Attach to the container to see the results in realtime.

•   "docker attach" This will allow us to attach to a background process to see what is going on.

•   $CONTAINER_ID The Id of the container we want to attach too.

    docker ps

    Check the process list to make sure it is running.

•   "docker ps" this shows all running process managed by docker

    $ docker stop $CONTAINER_ID

    Stop the container, since we don't need it anymore.

•   "docker stop" This stops a container

•   $CONTAINER_ID The Id of the container we want to stop.

    docker ps

    Make sure it is really stopped.

    Video:

    See the example in action

    Continue to the python_web_app example.

  Notes:

•   Docker daemon The docker daemon is started by sudo docker -d, Vagrant may have started the Docker daemon for you, but you will need to restart it this way if it was terminated. Otherwise it may give you Couldn't create Tag store: open /var/lib/docker/repositories: permission denied

  Building a python web app

The goal of this example is to show you how you can author your own docker images using a parent image, making changes to it, and then saving the results as a new image. We will do that by making a simple hello flask web application image.

Steps:

$ docker import shykes/pybuilder

We are importing the "shykes/pybuilder" docker image

$ URL=http://github.com/shykes/helloflask/archive/master.tar.gz

We set a URL variable that points to a tarball of a simple helloflask web app

$ BUILD_JOB=$(docker run -t shykes/pybuilder:1d9aab3737242c65 /usr/local/bin/buildapp $URL)

Inside of the "shykes/pybuilder" image there is a command called buildapp, we are running that command and passing the $URL variable from step 2 to it, and running the whole thing inside of a new container. BUILD_JOB will be set with the new container_id. "1d9aab3737242c65" came from the output of step 1 when importing image. also available from 'docker images'.

$ docker attach $BUILD_JOB
[...]

We attach to the new container to see what is going on. Ctrl-C to disconnect

$ BUILD_IMG=$(docker commit $BUILD_JOB _/builds/github.com/hykes/helloflask/master)

Save the changed we just made in the container to a new image called "_/builds/github.com/hykes/helloflask/master" and save the image id in the BUILD_IMG variable name.

$ WEB_WORKER=$(docker run -p 5000 $BUILD_IMG /usr/local/bin/runapp)

Use the new image we just created and create a new container with network port 5000, and return the container id and store in the WEB_WORKER variable.

$ docker logs $WEB_WORKER
 * Running on http://0.0.0.0:5000/

view the logs for the new container using the WEB_WORKER variable, and if everything worked as planned you should see the line "Running on http://0.0.0.0:5000/" in the log output.

Video:

See the example in action

Continue to the base commands

CONTRIBUTING

  Contributing to Docker

Want to hack on Docker? Awesome! There are instructions to get you started on the website: http://docker.io/gettingstarted.html

They are probably not perfect, please let us know if anything feels wrong or incomplete.

  Contribution guidelines

  Pull requests are always welcome

We are always thrilled to receive pull requests, and do our best to process them as fast as possible. Not sure if that typo is worth a pull request? Do it! We will appreciate it.

If your pull request is not accepted on the first try, don't be discouraged! If there's a problem with the implementation, hopefully you received feedback on what to improve.

We're trying very hard to keep Docker lean and focused. We don't want it to do everything for everybody. This means that we might decide against incorporating a new feature. However, there might be a way to implement that feature on top of docker.

  Discuss your design on the mailing list

We recommend discussing your plans on the mailing list before starting to code - especially for more ambitious contributions. This gives other contributors a chance to point you in the right direction, give feedback on your design, and maybe point out if someone else is working on the same thing.

  Create issues...

Any significant improvement should be documented as a github issue before anybody starts working on it.

  ...but check for existing issues first!

Please take a moment to check that an issue doesn't already exist documenting your bug report or improvement proposal. If it does, it never hurts to add a quick "+1" or "I have this problem too". This will help prioritize the most common problems and requests.

  Write tests

Golang has a great testing suite built in: use it! Take a look at existing tests for inspiration.

  Setting up a dev environment

Instructions that have been verified to work on Ubuntu 12.10,

Then run the docker daemon,

Run the go install command (above) to recompile docker.

COMMANDS

Contents:

  Base commands

  Running an interactive shell

# Download a base image
docker import base
# Run an interactive shell in the base image,
# allocate a tty, attach stdin and stdout
docker run -a -i -t base /bin/bash

  Starting a long-running worker process

# Run docker in daemon mode
(docker -d || echo "Docker daemon already running") &
# Start a very useful long-running process
JOB=$(docker run base /bin/sh -c "while true; do echo Hello world!; sleep 1; done")
# Collect the output of the job so far
docker logs $JOB
# Kill the job
docker kill $JOB

  Listing all running containers

docker ps

  Expose a service on a TCP port

# Expose port 4444 of this container, and tell netcat to listen on it
JOB=$(docker run -p 4444 base /bin/nc -l -p 4444)
# Which public port is NATed to my container?
PORT=$(docker port $JOB 4444)
# Connect to the public port via the host's public address
echo hello world | nc $(hostname) $PORT
# Verify that the network connection worked
echo "Daemon received: $(docker logs $JOB)"

Continue to the complete Command Line Interface

  Command Line Interface

  Docker Usage

$ docker
  Usage: docker COMMAND [arg...]
  A self-sufficient runtime for linux containers.
  Commands:
      attach    Attach to a running container
      commit    Create a new image from a container's changes
      diff      Inspect changes on a container's filesystem
      export    Stream the contents of a container as a tar archive
      history   Show the history of an image
      images    List images
      import    Create a new filesystem image from the contents of a tarball
      info      Display system-wide information
      inspect   Return low-level information on a container
      kill      Kill a running container
      login     Register or Login to the docker registry server
      logs      Fetch the logs of a container
      port      Lookup the public-facing port which is NAT-ed to PRIVATE_PORT
      ps        List containers
      pull      Pull an image or a repository to the docker registry server
      push      Push an image or a repository to the docker registry server
      restart   Restart a running container
      rm        Remove a container
      rmi       Remove an image
      run       Run a command in a new container
      start     Start a stopped container
      stop      Stop a running container
      tag       Tag an image into a repository
      version   Show the docker version information
      wait      Block until a container stops, then print its exit code

  attach

Usage: docker attach [OPTIONS]
Attach to a running container
  -e=true: Attach to stderr
  -i=false: Attach to stdin
  -o=true: Attach to stdout

  commit

Usage: docker commit [OPTIONS] CONTAINER [DEST]
Create a new image from a container's changes
-m="": Commit message

  diff

Usage: docker diff CONTAINER [OPTIONS]
Inspect changes on a container's filesystem

  export

Usage: docker export CONTAINER
Export the contents of a filesystem as a tar archive

  history

Usage: docker history [OPTIONS] IMAGE
Show the history of an image

  images

Usage: docker images [OPTIONS] [NAME]
List images
  -a=false: show all images
  -q=false: only show numeric IDs

  import

Usage: docker import [OPTIONS] URL|- [REPOSITORY [TAG]]

Create a new filesystem image from the contents of a tarball At this time, the URL must start with ``http`` and point to a single file archive (.tar, .tar.gz, .tgz, .bzip, .tar.xz, .txz) containing a root filesystem. If you would like to import from a local directory or archive, you can use the ``-`` parameter to take the data from standard in.

  info

Usage: docker info
Display system-wide information.

  inspect

Usage: docker inspect [OPTIONS] CONTAINER
Return low-level information on a container

  kill

Usage: docker kill [OPTIONS] CONTAINER [CONTAINER...]
Kill a running container

  login

Usage: docker login
Register or Login to the docker registry server

  logs

Usage: docker logs [OPTIONS] CONTAINER
Fetch the logs of a container

  port

Usage: docker port [OPTIONS] CONTAINER PRIVATE_PORT
Lookup the public-facing port which is NAT-ed to PRIVATE_PORT

  ps

Usage: docker ps [OPTIONS]
List containers
  -a=false: Show all containers. Only running containers are shown by default.
  -notrunc=false: Don't truncate output
  -q=false: Only display numeric IDs

  pull

Usage: docker pull NAME
Pull an image or a repository from the registry

  push

Usage: docker push NAME
Push an image or a repository to the registry

  restart

Usage: docker restart [OPTIONS] NAME
Restart a running container

  rm

Usage: docker rm [OPTIONS] CONTAINER
Remove a container

  rmi

Usage: docker rmi [OPTIONS] IMAGE
Remove an image
  -a=false: Use IMAGE as a path and remove ALL images in this path
  -r=false: Use IMAGE as a regular expression instead of an exact name

  run

Usage: docker run [OPTIONS] IMAGE COMMAND [ARG...]
Run a command in a new container
  -a=false: Attach stdin and stdout
  -c="": Comment
  -i=false: Keep stdin open even if not attached
  -m=0: Memory limit (in bytes)
  -p=[]: Map a network port to the container
  -t=false: Allocate a pseudo-tty
  -u="": Username or UID

  start

Usage: docker start [OPTIONS] NAME
Start a stopped container

  stop

Usage: docker stop [OPTIONS] NAME
Stop a running container

  tag

Usage: docker tag [OPTIONS] IMAGE REPOSITORY [TAG]
Tag an image into a repository
  -f=false: Force

  version

Usage: docker version
Show the docker version information

  wait

Usage: docker wait [OPTIONS] NAME
Block until a container stops, then print its exit code.

FAQ

  Most frequently asked questions.

1. How much does Docker cost?

Docker is 100% free, it is open source, so you can use it without paying.

2. What open source license are you using?

We are using the Apache License Version 2.0, see it here: https://github.com/dotcloud/docker/blob/master/LICENSE

3. Does Docker run on Mac OS X or Windows?

Not at this time, Docker currently only runs on Linux, but you can use VirtualBox to run Docker in a virtual machine on your box, and get the best of both worlds. Check out the MacOSX and Windows intallation guides.

4. How do containers compare to virtual machines?

They are complementary. VMs are best used to allocate chunks of hardware resources. Containers operate at the process level, which makes them very lightweight and perfect as a unit of software delivery.

5. Can I help by adding some questions and answers?

Definitely! You can fork the repo and edit the documentation sources.

42. Where can I find more answers?

You can find more answers on:

•   IRC: docker on freenode

•   Github

•   Ask questions on Stackoverflow

•   Join the conversation on Twitter

    Looking for something else to read? Checkout the hello_world example.

AUTHOR
Team Docker

COPYRIGHT
2013, Team Docker