Install Docker on ubuntu for developers

Docker is an open-source project that provides an open platform for developers and sysadmins to build, package, and run applications anywhere as a lightweight container. Docker automates the deployment of applications inside software containers.

Docker is a great tool for developers. The key reason why is that it removes friction incurred when setting up your development laptop for different development environments, especially for Polyglot developers!.

In this post, we’ll go through the basics of installing and getting up and running with Docker on a your Ubuntu Desktop to start developing with Docker

What is Docker ?

If you’re a developer who supports many different projects, all written in different programming languages, using different runtime libraries and frameworks in those languages. For instance, PHP websites developed using Laravel, others using CakePHP, yet others using the YII Framework and then there are a few WordPress based websites. All using slightly different versions of the Frameworks because customers don’t want to upgrade for a variety of different reasons.

You also have to support a few Node.js applications, and we all know how often Node upgrades its versions. We haven’t even got into to the debate regarding a myriad of the latest hot trend in JavaScript UI frameworks!

It can be an absolute nightmare configuring your workstation just to fix a 5-minute bug. It can take hours uninstalling tweaking, troubleshooting and reconfiguring. Time which is better spent hyping some Web Framework on Twitter!

Docker to the rescue

Docker drastically simplifies this process. Reducing the need for developers to be configuration experts enabling them to focus on solving problems using code!

If you’re running Mac or Windows installing Docker is a relatively simple process of quite literally following a wizard. Read instructions on how to install docker on Windows or install docker on Mac OSX. You should be up and running is minutes.

Installing docker on ubuntu

When it comes to installing Docker on Ubuntu, things are slightly trickier, and although the instructions on the docker website are great and will get you up and running quickly. I have found a couple of quirks that aren’t always that obvious. I will aim to cover these and keep this post updated as I find them.

Don’t install docker from the default Ubuntu repositories

How to uninstall old versions of docker

There are a number of different versions of docker available. As with any Open Source library, they tend to go through different iterations before finally getting to a state where they either get funding and are able to market the product and get it ready for the market or they subject to the whims and desires or whoever maintains them or they just die!

Fortunately for docker, it gained mass appeal and adoption. Unfortunately, most package repositories still have the much older versions of a package available for public download, and a number of tutorials on the internet provide guides and tutorials for installing these older versions.

So firstly, check whether you have any older versions installed. ( Open a terminal window ctrl + alt + t ).

Execute,docker -v if the terminal responds with a version number lower than Docker version 17.05.0-ce, build 89658be you need to remove it. If you have a higher version or build then you’re good to go.

To check your docker version, use the following grep command

Shell


Which should return with one of the following: docker , docker-engine or docker.io

How to remove older versions of docker

The completely remove and purge the package replacing [package name] with the name of the package you have installed :

Shell

How to install Docker on Ubuntu

There are a number of ways to install docker on Ubuntu, I’ll run through my three favourite ways to install it.

How to install Docker using Linuxbrew

if you have come from a Mac OSX environment to Linux, you may be familiar with Homebrew – the unofficial package manager for Mac OSX.

The good news is that this is now also available on Linux and is known as Linuxbrew. You can also learn how to use Homebrew Package Manager on Linux .

Once you have Linuxbrew installed you simply install docker using the the brew command

Shell

How to install docker using Snap

“Snap” refers to both the snap command and a snap installation file. A snap bundles an application and all its dependencies into one compressed file. The dependencies might be library files, web or database servers, or anything else an application must have to launch and run.

Shell

Warning

I have grown to become less of a fan of Snap and have now started to avoid installing things via snaps. The reason being is that I have found some issues with Snap installed apps failing then causing Ubuntu login loops which I have yet to find a recovery for.

How to install Docker from the Docker Repository

Once you have completed removing or ensuring you don’t have any older versions installed on your development machine, then you should be ready to install Docker Community edition .

The instructions below are reproduced from the Official Docker Website, but please be advised these may change and we urge you to double-check on the docker website.

There is a complete script to automate the installation of docker available from https://get.docker.com/ you can download this script and run it on your machine.

Please be aware that this install process is typical for 64-Bit laptops or desktops using Ubuntu 16.04 LTS. 

Check the docker website  for other configuration options

Shell

After completing the steps above you should Log out and log back into your laptop for the settings to take effect.

How to run your first docker images

You should now be in state to start playing and learning how to use docker.

Check out common docker commands and terms

There are three ways to test if docker is working.

1. Hello World

In typical programmer tradition we’ll run a “Hello World” application docker style.

To run the Hello-World sample, open a terminal window ctrl + alt + t

Execute docker run hello-world you should see a response similar to;

2. Busy Box

We’ll run a small embedded Linux distro called : BusyBox .

BusyBox combines tiny versions of many common UNIX utilities into a single small executable. It provides replacements for most of the utilities you usually find in GNU fileutils, shellutils etc.

The utilities in BusyBox generally have fewer options than their full-featured GNU cousins; however, the options that are included provide the expected functionality and behave very much like their GNU counterparts. BusyBox provides a fairly complete environment for any small or embedded system.

To run an instance of Busybox,  open a terminal window. ( ctrl + alt + t )

Execute docker run busybox echo "hello from threenine.co.uk" and you should see a result similar to:

3. Docker-whale

If you’re feeling a little more adventurous you can use the docker client to search for an image and run it. As an example, from the terminal use this docker search threenine should return a list of the docker images we have created.

At the time writing this post, it returns a list of 4 images, of which the specific one of interest will be,threenine/docker-whale which is a result of following the docker tutorial for creating images.

Let’s go ahead and run that image docker run threenine/docker-whale

Install Docker Compose

docker-compose is a separate binary which is best downloaded directly from the project’s GitHub releases. Most popular Linux distributions do include Compose in their package managers but it can be significantly outdated.

Head to Docker Compose’s releases page and take note of the latest version number. At the time of writing, it was 1.29.2.

Substitute the version you see instead of 1.29.2 in the command below. This will download the right binary for your system and drop it into /usr/local/bin.

Shell

You’ll now be able to use the docker-compose command in your terminal. Try running docker-compose --version to check.

Video

Conclusion

Docker should now be installed on your development machine and you should now be able to create and use docker images. Docker will help to simplify common development configuration scenarios and help to isolate specific configurations to containerised machines.

Docker can be used in a wide variety of environments, the requirements of the infrastructure are no longer linked with the environment of the application.

Latest posts by Gary Woodfine (see all)