Documentation

Setup

If you use Linux, setting up Docker is fairly easy. You can find great instructions straight from Docker's website here. You can also set up Docker on MacOS and Windows - it's a little more complicated, so I recommend using Vagrant's new Docker support feature.

Using the repository

Docker's repository of images is one of it's best features. The images can be downloaded using the pull command and used as the basis of containers for running applications or programming environments (ie. with an ubuntu image you can run containers with ubuntu).

If you want to download an ubuntu Docker image, all you have to do is type this into terminal:

$ docker pull ubuntu

If you get a permission denied error, add sudo before Docker in your commands, like below:

$ sudo docker pull ubuntu

Pulling Docker images for the first time is similar to cloning a github repository. With the line above, you downloaded an ubuntu image with various versions of ubuntu, such as 14.04, 13.10 and so on. It probably took a few minutes.

You can also be more specific and download only the version you need. In Docker, versions are marked with tags. For example, to download a specific debian box, write:

Congratulations! You've just run your first command on Docker container. To try your container interactively, use:

$ docker run -t ubuntu:14.04

or

$ docker run -i -t ubuntu:14:04 /bin/bash

Now you have the newest ubuntu with root access at your fingertips. Try some commands like pwd or cd to make sure that it works.

You can close it anytime by typing Ctrl-D or exit.

Running a Redis container

Now that you know the basics, we can proceed with a more sophisticated example. Imagine that you want to run Redis in our container. (Redis is simple but powerful key-value store. You can read more about it here.)

You can find its image in Docker's registry using Docker's search command:

And you're done! You can check if your Redis container works with Redis desktop manager or Webdis - both are pretty cool tools that you should check out if you use Redis.

Getting more info about Docker containers

To see which Docker containers are on your computer, type:

$ docker ps -a

This will show you:

CONTAINER ID - every container has unique id

IMAGE - image that container is based on

NAMES - names given to your container (Docker gives funny names to your containers if you don't provide your own by passing --name containername_ in the run command)

COMMAND - what command container runs inside

CREATED - when the container was created

STATUS - containers can be in two states: exited or running

PORTS - exposed and forwarded ports

That's a lot's of information! But wait, there's more. Let's spy a bit on our container with the inspect command.

$ docker inspect <docker_container_id or name>

If you run a Redis container with the --name flag, you can inspect it with the below command:

$ docker inspect redis

This prints a lot of useful information, including the configuration of the container, its environment variables, forwarded ports, mounted volumes, container constraints, and so on. Below is only small fragment of what you can see: