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!.
If you’re a developer who supports many different projects, all written in different programming languages, using different runtime libraries and frameworks in those langunages. 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.
What about python? Is this app you’re working on 2.7 or 3 ? What web server is the site using ? is it Apache or Nginx? What Database Management system is it using? Is it mySQL ? MariaDB, MS SQL, PostgresSQL, Redis or MongoDB? What about the Messaging is it RabbitMQ, MSMQ or something else nobody else is using?
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 the things they like doing 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 instuctions 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.
Uninstall old versions
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 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) and execute
docker -v, if the terminal responds with anythin other than
Docker version 17.05.0-ce, build 89658be then you need to remove it. If you have a higher version or build then you’re good to go.
If you have an older version installed. use
dpkg -l | grep -i docker to identify the version, this should return with either :
The completely remove and purge the package replacing
[package name] with the name of the package you have installed :
sudo apt-get remove [package name]
sudo apt-get purge -y [package name]
sudo apt-get autoremove -y --purge [package name]
sudo apt-get autoclean
# delete any old images
sudo rm -rf /var/lib/docker
# delete form apparmor
sudo rm /etc/apparmor.d/docker
# delete any old docker users groups
sudo groupdel docker
Your development machine should now be ready to install Docker Communit edition . We’ll reproduce the instructions here, 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 Dekstops using ubuntu 16.04 LTS. If you’re installing on anything other then check the docker website
# update repositories
sudo apt update
# Install packages to allow apt to use a repository over https
sudo apt install apt-transport-https ca-certificates curl software-properties-common
# Add Docker’s official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# Verify that you now have the key with the fingerprint
sudo apt-key fingerprint 0EBFCD88
# add repository for 64bit
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# update repositories
sudo apt update
# install docker
sudo apt install docker-ce
# enable docker to run without sudo
# create a docker group
sudo groupadd docker
# add your current user to that group
sudo usermod -aG docker $USER
After completing the steps above you should Log out and log back into your laptop for the settings to take effect.
Run your first docker images
You should now be in state to start playing with docker.
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) and 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 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) and execute
docker run busybox echo "hello from threenine.co.uk" and you should see result similar to:
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
docker search threenine this 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
Docker should now be installed on your development machine and you should now be able to create and use docker images.
A unique background as business owner, marketing, software development and business development ensures that he can offer the optimum business consultancy services across a wide spectrum of business challenges.