Docker Tutorial: Getting Started

Justyna IlczukJustyna Ilczuk

Since we started using Docker here at Syncano, we've become avid fans.

Here's some of our best knowledge on getting started with Docker. If you're not sure about what Docker is or whether you should use it, check out the last post in this series.


Docker has great documentation and a useful interactive online tutorial.


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:

$ docker pull debian:squeeze

To see what Docker images are available on your machine, write:

$ docker images

ubuntu                           14.10                                      f14704ad99b8    3 days ago          226.8 MB  
ubuntu                           utopic                                     f14704ad99b8    3 days ago          226.8 MB  

Docker run command

After downloading an image, you can run it using Docker's run command, which looks like:

$ docker run [OPTIONS] IMAGE[:TAG] [COMMAND] [ARG...]

Use this to test the image with a simple ls command run on your Docker image:

$ docker run -t ubuntu:14.04 ls

bin   dev  home  lib64  mnt  proc  run   srv  tmp  var  
boot  etc  lib   media  opt  root  sbin  sys  usr  

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

$ docker run -t ubuntu:14.04


$ 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:

$ docker search redis

You'll notice the command prints almost eight houndred images!

$ docker search redis | wc -l

Choose one of the most popular images: dockerfile/redis.

Next, create your container. There are three requirements:

The first requirement is very simple. Just pass a -d flag to your docker run command.

For the second requirement, map a host directory to a directory in your container where it stores data.

From this readme on dockerfile/redis you probably know that a Redis image is configured to store data in the /data directory. That means you must:

Creating a directory is simple:

$ mkdir /var/docker/redis

You can mount by:

$ docker run -v /host_directory:/container_directory docker_image

$ docker run -d -v /var/docker/redis:/data dockerfile/redis

You can find more information about docker volumes here.

The last part is networking. Redis uses port 6379 by default, so you have to forward this port to make it accessible from your computer. To forward $CONTAINERPORT to $HOSTPORT on your computer use:

$ docker run -p $HOSTPORT:$CONTAINERPORT --name CONTAINER -t someimage

For this example, it should look like:

$ docker run -d -v /var/docker/redis:/data -p 6379:6379 --name=redis dockerfile/redis

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:

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:

"NetworkSettings": {
    "Bridge": "docker0",
    "Gateway": "",
    "IPAddress": "",
    "IPPrefixLen": 16,
    "PortMapping": null,
    "Ports": {
        "6379/tcp": [
                "HostIp": "",
                "HostPort": "6379"
"Path": "redis-server",
"ProcessLabel": "",
"ResolvConfPath": "/etc/resolv.conf",
"State": {
    "ExitCode": 0,
    "FinishedAt": "0001-01-01T00:00:00Z",
    "Paused": false,
    "Pid": 13335,
    "Running": true,
    "StartedAt": "2014-10-03T10:16:20.834865727Z"
"Volumes": {
    "/data": "/var/docker/redis"

The other valuable commands are:

$ docker logs redis

Which will let you see what container prints to STDIO and STDOUT, and

$ docker top redis

Which tells you what processes are currently running on you Docker container. It's similar to a unix tool called top.

What to do next

We've covered so much information about Docker, yet we've only scratched the surface!

To learn more, check out this docker cheatsheet and the materials from warsjawa workshops - they will blow you away with helpful information!

Build powerful apps in half the time

Use our serverless platform to set up your backend in minutes.

Learn more