How to manage Docker containers on Ubuntu

While full hardware virtualization such as KVM, Xen or Hyper-V is great at running fully isolated instances of multiple operating systems on a physical host, it comes with various overheads in terms of performance, resource, and provisioning time. Depending on your use cases, full machine virtualization may actually not be necessary.

An alternative lightweight virtualization approach is so-called container-based virtualization which provides operating system level virtualization. Without the overhead of running virtual machines, the container technology allows you to run multiple instances of full Linux operating system within lightweight container sandbox. Containers can be very useful when you set up a reproducible development/test environment or deploy applications within secure sandboxes.

Docker is an open-source tool which was developed to facilitate the deployment of containers in Linux environment. Docker is fast becoming a de-facto standard for container technologies, being embraced in major Linux distros such as Ubuntu and Red Hat.

In this tutorial, I am going to demonstrate how to manage Linux containers with Docker on Ubuntu 14.10. Note that instructions may be slightly different for earlier versions of Ubuntu. If you want to try out Docker on Fedora or CentOS, refer to this tutorial.

At this time, the Docker package available on Ubuntu only supports 64-bit systems. To run it on 32-bit machine, you will need to build 32-bit version of Docker from source.

Install Docker

Installing Docker is easy with apt-get command.

$ sudo apt-get install

To allow non-root user to run Docker, add yourself to docker group. The command below will allow the current user to run Docker without root permission.

$ sudo usermod -a -G docker $USER

Log out and then re-login to activate group membership change.

Next, edit the Docker configuration file to update the location of the Docker binary.

$ sudo vi /etc/default/docker

Note that on Ubuntu 14.04 and earlier, the Docker configuration file is loated at /etc/default/, and its binary is /usr/bin/ (due to naming conflict with a system tray app called docker).

Restart Docker service.

$ sudo service docker restart
(or sudo service restart)

Manage Docker Containers

If you want to start a new Docker container of Ubuntu operating system, first pull Ubuntu Docker image first. The command below will download Docker image over a network, and cache it locally. The first time you run this command, it will take a couple of minutes to finish.

$ docker pull ubuntu

You can start a Ubuntu Docker in an interactive mode as follows.

$ docker run -i -t ubuntu /bin/bash

In the above command, the last argument "/bin/bash" is the command that will be executed inside a container once it is launched, in this case, a simple bash shell. So it will launch a Ubuntu container immediately (which is the beauty of containers!), and give you a shell prompt inside the container. At this point, you should be able to access a full Ubuntu operating system inside a sandboxed environment.

To exit a Docker container, type "exit" at the prompt inside the container.

You can launch containers in different flavors. For example, to start a Fedora container:

$ docker run -i -t fedora /bin/bash

If a Fedora Docker image is not available locally, the command will automatically download the image first, and then launch a Docker. So it will take a couple of minutes to start a new Docker. Subsequent launch of additional Dockers of the same image will be finished instantly.

If you want to launch a container with a particular distro release, you can also do that. For example, to start a Ubuntu 13.04 Docker:

$ docker run -i -t ubuntu:13.04 /bin/bash

To see a list of currently running Docker containers, use the following command.

$ docker ps

If you want to see a list of all (active or terminated) Docker containers, run this command instead.

$ docker ps -a

Container Networking

Docker uses Linux bridge to interconnect containers with each other, and to connect them to external networks. After installing Docker, you should see docker0 Linux bridge created automatically by default. Every container you create will be connected to docker0 bridge interface.

Custom Linux Bridge

If you want, you can use a custom Linux bridge to interconnect containers. For that, you can create a custom bridge and configure it as follows. You can assign a separate subnet to the bridge, and have Dockers assigned IP addresses from the subnet. I am going to use as a Docker subnet.

$ sudo apt-get install bridge-utils
$ sudo brctl addbr br0
$ sudo ifconfig br0 netmask

To make the custom bridge used by Docker, add "-b=br0" to DOCKER_OPTS variable in /etc/default/, and restart Docker service.

$ sudo service docker restart
(or sudo service restart)

At this point, any new container will be connected to br0, and its IP address will automatically be assigned from

Other Customizations

There are several other ways to customize the default network settings of Docker, mostly by tweaking DOCKER_OPTS variable in /etc/default/

  • "-dns -dns": specify the DNS servers used by a container.
  • "-icc=false": make containers isolated from each other.

If you want to interconnect Docker containers across different hosts, I strongly recommend using weave, a powerful Docker networking tool.


1. You encounter the following error when running docker command.

dial unix /var/run/docker.sock: no such file or directory

The error may be because Docker daemon is not running. Check the status of Docker daemon, and make sure to start it first.

$ sudo service docker status
$ sudo service docker start

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

6 thoughts on “How to manage Docker containers on Ubuntu

  1. I ran this under VMWare which might account for the second issue, but I doubt the first. What did I do wrong? After installing the package and giving the first few commands (above) to initialize things I get:

    $ docker pull
    The program 'docker' is currently not installed. You can install it by typing:
    sudo apt-get install docker
    $ pull

    Usage: docker pull NAME

    Pull an image or a repository from the registry

    -t, --tag="": Download tagged image in repository
    $ pull ubuntu
    2014/05/02 14:02:04 dial unix /var/run/docker.sock: no such file or directory
    $ uname -a
    Linux 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:08:14 UTC 2014 i686 i686 i686 GNU/Linux

    $ sudo apt-get install docker
    $ docker pull
    Segmentation Fault or Critical Error encountered. Dumping core and aborting.
    Aborted (core dumped)

    • In Ubuntu/Debian, the command "docker" is taken by something else. So do not install "apt-get install docker" nor run "docker" command. You are supposed to run "" command.

      As I mentioned in the article, to solve the "dial unix /var/run/docker.sock: no such file or directory" error, make sure that docker daemon is running in the background:

      $ ps aux|grep docker
      root       966  0.0  0.1 361500  9312 ?        Sl   09:09   0:00 /usr/bin/ -d -dns -dns

      To start a docker daemon:

      $ sudo service start
      • Here's the problem:

        $ sudo tail -4 /var/log/upstart/
        2014/05/02 14:36:55 The docker runtime currently only supports amd64 (not 386). This will change in the future. Aborting.
        2014/05/02 14:36:55 The docker runtime currently only supports amd64 (not 386). This will change in the future. Aborting.
        2014/05/02 14:36:55 The docker runtime currently only supports amd64 (not 386). This will change in the future. Aborting.
        2014/05/02 14:36:55 The docker runtime currently only supports amd64 (not 386). This will change in the future. Aborting.

  2. Great tutorial, I have my first container up and running in less than 5 minutes.

    I wish to see more about docker soon, how to run multiple containers in the cloud, integration with virtual switches, fine tuning, etc.


Leave a comment

Your email address will not be published. Required fields are marked *