In my recent article I described the process of setting up the Sql Server vNext on a Linux machine and the Docker was the most crucial tool used for that. Although the Docker server was required, I didn’t show you how to install it properly. This article should fill the hole.
Requirements
The only assumption for this article is that you already have an instance of Ubuntu 16.04 (64-bit) and at most 30 minutes of spare time. So, ready, steady and go!
Installation process
Let’s begin with checking whether curl is available in the system. I prefer to use which
command for such a purpose – it shows a path for an executable linked with a passed command. If the which
returns nothing I know the command doesn’t exists, at least until it’s installed. Please take a look at the console output below. It illustrates the case when curl is needed to be installed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
vts@vts:~$ which ls /bin/ls vts@vts:~$ which curl vts@vts:~$ sudo apt-get install curl [sudo] password for vts: Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: curl 0 upgraded, 1 newly installed, 0 to remove and 262 not upgraded. Need to get 139 kB of archives. After this operation, 338 kB of additional disk space will be used. Get:1 http://pl.archive.ubuntu.com/ubuntu xenial-updates/main amd64 curl amd64 7.47.0-1ubuntu2.2 [139 kB] Fetched 139 kB in 0s (273 kB/s) Selecting previously unselected package curl. (Reading database ... 174198 files and directories currently installed.) Preparing to unpack .../curl_7.47.0-1ubuntu2.2_amd64.deb ... Unpacking curl (7.47.0-1ubuntu2.2) ... Processing triggers for man-db (2.7.5-1) ... Setting up curl (7.47.0-1ubuntu2.2) ... |
When the curl is ready to work I will use it for adding official GPG key from Docker’s server:
1 2 3 |
vts@vts:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - [sudo] password for vts: OK |
lsb_release
command for obtaining Ubuntu distribution name which is needed for pointing out proper repository. I follow this suggestion:
1 2 3 4 |
vts@vts:~$ lsb_release -cs xenial vts@vts:~$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" [sudo] password for vts: |
When OS has any new repository it is always necessary to get information about packages which the repository serves. Let’s do it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
vts@vts:~$ sudo apt-get update [sudo] password for vts: Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB] Hit:2 http://pl.archive.ubuntu.com/ubuntu xenial InRelease Hit:3 http://pl.archive.ubuntu.com/ubuntu xenial-updates InRelease Hit:4 http://pl.archive.ubuntu.com/ubuntu xenial-backports InRelease Get:5 http://security.ubuntu.com/ubuntu xenial-security/main amd64 DEP-11 Metadata [59,2 kB] Get:6 http://security.ubuntu.com/ubuntu xenial-security/main DEP-11 64x64 Icons [54,2 kB] Get:7 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 DEP-11 Metadata [40,6 kB] Get:8 http://security.ubuntu.com/ubuntu xenial-security/universe DEP-11 64x64 Icons [56,2 kB] Get:9 https://download.docker.com/linux/ubuntu xenial InRelease [29,5 kB] Get:10 https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages [1966 B] Fetched 344 kB in 2s (120 kB/s) Reading package lists... Done |
As expected, the Docker repositories responded with lists of available packages. It means the Docker is ready to be installed:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
vts@vts:~$ sudo apt-get install docker-ce [sudo] password for vts: Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: aufs-tools cgroupfs-mount git git-man liberror-perl Suggested packages: git-daemon-run | git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb git-arch git-cvs git-mediawiki git-svn The following NEW packages will be installed: aufs-tools cgroupfs-mount docker-ce git git-man liberror-perl 0 upgraded, 6 newly installed, 0 to remove and 262 not upgraded. Need to get 24,4 MB of archives. After this operation, 122 MB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://pl.archive.ubuntu.com/ubuntu xenial/universe amd64 aufs-tools amd64 1:3.2+20130722-1.1ubuntu1 [92,9 kB] Get:2 http://pl.archive.ubuntu.com/ubuntu xenial/universe amd64 cgroupfs-mount all 1.2 [4970 B] Get:3 http://pl.archive.ubuntu.com/ubuntu xenial/main amd64 liberror-perl all 0.17-1.2 [19,6 kB] Get:4 http://pl.archive.ubuntu.com/ubuntu xenial-updates/main amd64 git-man all 1:2.7.4-0ubuntu1.1 [735 kB] Get:5 https://download.docker.com/linux/ubuntu xenial/stable amd64 docker-ce amd64 17.06.0~ce-0~ubuntu [20,5 MB] Get:6 http://pl.archive.ubuntu.com/ubuntu xenial-updates/main amd64 git amd64 1:2.7.4-0ubuntu1.1 [3068 kB] Fetched 24,4 MB in 5s (4286 kB/s) Selecting previously unselected package aufs-tools. (Reading database ... 174205 files and directories currently installed.) Preparing to unpack .../aufs-tools_1%3a3.2+20130722-1.1ubuntu1_amd64.deb ... Unpacking aufs-tools (1:3.2+20130722-1.1ubuntu1) ... Selecting previously unselected package cgroupfs-mount. Preparing to unpack .../cgroupfs-mount_1.2_all.deb ... Unpacking cgroupfs-mount (1.2) ... Selecting previously unselected package docker-ce. Preparing to unpack .../docker-ce_17.06.0~ce-0~ubuntu_amd64.deb ... Unpacking docker-ce (17.06.0~ce-0~ubuntu) ... Selecting previously unselected package liberror-perl. Preparing to unpack .../liberror-perl_0.17-1.2_all.deb ... Unpacking liberror-perl (0.17-1.2) ... Selecting previously unselected package git-man. Preparing to unpack .../git-man_1%3a2.7.4-0ubuntu1.1_all.deb ... Unpacking git-man (1:2.7.4-0ubuntu1.1) ... Selecting previously unselected package git. Preparing to unpack .../git_1%3a2.7.4-0ubuntu1.1_amd64.deb ... Unpacking git (1:2.7.4-0ubuntu1.1) ... Processing triggers for libc-bin (2.23-0ubuntu5) ... Processing triggers for man-db (2.7.5-1) ... Processing triggers for ureadahead (0.100.0-19) ... Processing triggers for systemd (229-4ubuntu16) ... Setting up aufs-tools (1:3.2+20130722-1.1ubuntu1) ... Setting up cgroupfs-mount (1.2) ... Setting up docker-ce (17.06.0~ce-0~ubuntu) ... Setting up liberror-perl (0.17-1.2) ... Setting up git-man (1:2.7.4-0ubuntu1.1) ... Setting up git (1:2.7.4-0ubuntu1.1) ... Processing triggers for libc-bin (2.23-0ubuntu5) ... Processing triggers for systemd (229-4ubuntu16) ... Processing triggers for ureadahead (0.100.0-19) ... |
It’s almost ready. Before I run the first container it’s worth to add my current user to the docker group. As a result I will be allowed to use docker without root privileges (just after the reboot).
1 2 3 4 |
vts@vts:~$ sudo usermod -aG docker ${USER} [sudo] password for vts: vts@vts:~$ groups ${USER} vts : vts adm cdrom sudo dip plugdev lpadmin sambashare docker |
The groups
command shows clearly the user is now in docker group. It means it’s time for the final attempt – running hello-world container.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
vts@vts:~$ sudo docker run hello-world [sudo] password for vts: Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world b04784fba78d: Pull complete Digest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://cloud.docker.com/ For more examples and ideas, visit: https://docs.docker.com/engine/userguide/ |
Success! I hope I was right at the the beginning that the entire process takes less than 30 minutes.
Summary
The Docker installation on Ubuntu 16.04 is simple task. Most of the time is consumed by repository preparation, but when this step is finished we are on a good way to have Docker ready to work. I hope this kind of illustration was helpful for you and made you work easier.
Author: Mateusz Chmielewski
Senior software developer at VTS Software.
One Reply to “Installation of Docker CE on Ubuntu 16.04”