Install Docker on Ubuntu Server LTS 18.04 - CentLinux


Friday, 24 January 2020

Install Docker on Ubuntu Server LTS 18.04

Install Docker on Ubuntu Server LTS 18.04

In this article, you will learn how to install Docker on Ubuntu 19 server and execute some basic commands on that Docker host.

Docker is a set of Platform as a Service (PaaS) products that use operating system level virtualization to deliver software in packages called Containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels. All containers are run by a single operating-system kernel and are thus more lightweight than virtual machines. (Courtesy: Wikipedia)

The software that hosts the containers is called Docker Engine. Docker Engine was initially developed in 2013 and now it is maintained by Docker, Inc.

Docker is a Freemium product and available in both Enterprise (commericial) and Community (free) editions.


This Article Provides:


    Docker Features:

    Some of the core features of Docker are.

    • Easy and Faster Configuration
    • Increase productivity
    • Application Isolation
    • Routing Mesh
    • Swarm - A cluster of Docker host machines
    • Security Management
    • Services


    Environment Specification:

    We are using a Ubuntu virtual machine with following specification.

    • CPU - 3.4 Ghz (2 cores)
    • Memory - 2 GB
    • Storage - 40 GB
    • Operating System - Ubuntu Server LTS 18.04
    • Hostname -
    • IP Address - /24
    • Admin User - ahmer


    Updating Installed Packages on Ubuntu 18.04:

    Connect with as ahmer user by using a ssh tool like PuTTY.

    Update existing software packages using apt command.

    ahmer@docker-01:~$ sudo apt update Hit:1 disco InRelease Get:2 disco-updates InRelease [97.5 kB] Get:3 disco-backports InRelease [88.8 kB] Get:4 disco-security InRelease [97.5 kB] Fetched 284 kB in 3s (88.5 kB/s) Reading package lists... Done Building dependency tree Reading state information... Done 84 packages can be upgraded. Run 'apt list --upgradable' to see them.

    There are 84 package upgrades are available. Install these upgrades by using following command.

    ahmer@docker-01:~$ sudo apt upgrade ... Setting up keyboard-configuration (1.178ubuntu12.1) ... Your console font configuration will be updated the next time your system boots. If you want to update it now, run 'setupcon' from a virtual console. update-initramfs: deferring update (trigger activated) Setting up openssl (1.1.1b-1ubuntu2.4) ... Setting up cloud-guest-utils (0.31-0ubuntu1.2) ... Setting up sg3-utils (1.42-2ubuntu1.18.04.1) ... Setting up initramfs-tools-bin (0.131ubuntu19.2) ... Setting up librados2 (13.2.6-0ubuntu0.18.04.4) ... Setting up apt-utils (1.8.3) ... Setting up libdevmapper-event1.02.1:amd64 (2:1.02.145-4.1ubuntu4.2) ... Setting up liblvm2app2.2:amd64 (2.02.176-4.1ubuntu4.2) ... Setting up libldap-2.4-2:amd64 (2.4.47+dfsg-3ubuntu2.2) ... Setting up systemd (240-6ubuntu5.8) ... Installing new version of config file /etc/dhcp/dhclient-enter-hooks.d/resolved ... Setting up (0.98-0ubuntu1~18.04.1) ... Setting up console-setup-linux (1.178ubuntu12.1) ... Setting up initramfs-tools-core (0.131ubuntu19.2) ... Setting up snapd (2.42.1+18.04) ... Installing new version of config file /etc/apparmor.d/usr.lib.snapd.snap-confine.real ... Installing new version of config file /etc/xdg/autostart/snap-userd-autostart.desktop ... snapd.failure.service is a disabled or a static unit, not starting it. snapd.snap-repair.service is a disabled or a static unit, not starting it. Setting up systemd-sysv (240-6ubuntu5.8) ... Setting up console-setup (1.178ubuntu12.1) ... update-initramfs: deferring update (trigger activated) Setting up cloud-init (19.3-41-gc4735dd3-0ubuntu1~18.04.1) ... Installing new version of config file /etc/cloud/templates/ntp.conf.debian.tmpl ... Setting up initramfs-tools (0.131ubuntu19.2) ... update-initramfs: deferring update (trigger activated) Setting up ubuntu-minimal (1.431.1) ... Setting up libnss-systemd:amd64 (240-6ubuntu5.8) ... Setting up sg3-utils-udev (1.42-2ubuntu1.18.04.1) ... update-initramfs: deferring update (trigger activated) Setting up friendly-recovery (0.2.39ubuntu0.18.04.1) ... Sourcing file `/etc/default/grub' Sourcing file `/etc/default/grub.d/50-curtin-settings.cfg' Sourcing file `/etc/default/grub.d/init-select.cfg' Generating grub configuration file ... Found linux image: /boot/vmlinuz-5.0.0-38-generic Found initrd image: /boot/initrd.img-5.0.0-38-generic done Setting up libpam-systemd:amd64 (240-6ubuntu5.8) ... Setting up ubuntu-standard (1.431.1) ... Setting up liblvm2cmd2.02:amd64 (2.02.176-4.1ubuntu4.2) ... Setting up dmeventd (2:1.02.145-4.1ubuntu4.2) ... dm-event.service is a disabled or a static unit not running, not starting it. Setting up lvm2 (2.02.176-4.1ubuntu4.2) ... update-initramfs: deferring update (trigger activated) Setting up ubuntu-server (1.431.1) ... Processing triggers for install-info (6.5.0.dfsg.1-4build1) ... Processing triggers for mime-support (3.60ubuntu1) ... Processing triggers for libc-bin (2.29-0ubuntu2) ... Processing triggers for rsyslog (8.32.0-1ubuntu7) ... Processing triggers for man-db (2.8.5-2) ... Processing triggers for plymouth-theme-ubuntu-text (0.9.4-1ubuntu1) ... update-initramfs: deferring update (trigger activated) Processing triggers for dbus (1.12.12-1ubuntu1.1) ... Processing triggers for initramfs-tools (0.131ubuntu19.2) ... update-initramfs: Generating /boot/initrd.img-5.0.0-38-generic cryptsetup: WARNING: The initramfs image may not contain cryptsetup binaries nor crypto modules. If that's on purpose, you may want to uninstall the 'cryptsetup-initramfs' package in order to disable the cryptsetup initramfs integration and avoid this warning.


    Installing Docker on Ubuntu 18.04:

    Docker is available in apt repository, therefore, we can easily install it on Ubuntu server by using a single apt command.

    ahmer@docker-01:~$ sudo apt install Reading package lists... Done Building dependency tree Reading state information... Done The following package was automatically installed and is no longer required: libdumbnet1 Use 'sudo apt autoremove' to remove it. The following additional packages will be installed: bridge-utils cgroupfs-mount containerd dns-root-data dnsmasq-base pigz runc ubuntu-fan Suggested packages: ifupdown aufs-tools debootstrap docker-doc rinse zfs-fuse | zfsutils The following NEW packages will be installed: bridge-utils cgroupfs-mount containerd dns-root-data dnsmasq-base pigz runc ubuntu-fan 0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded. Need to get 52.5 MB of archives. After this operation, 258 MB of additional disk space will be used. Do you want to continue? [Y/n] Y Get:1 disco/universe amd64 pigz amd64 2.4-1 [57.4 kB] Get:2 disco/main amd64 bridge-utils amd64 1.6-2ubuntu1 [30.5 kB] Get:3 disco/universe amd64 cgroupfs-mount all 1.4 [6,320 B] Get:4 disco/universe amd64 runc amd64 1.0.0~rc7+git20190403.029124da-0ubuntu1 [1,904 kB] Get:5 disco/universe amd64 containerd amd64 1.2.6-0ubuntu1 [19.4 MB] Get:6 disco/main amd64 dns-root-data all 2018091102 [5,472 B] Get:7 disco/main amd64 dnsmasq-base amd64 2.80-1ubuntu1 [314 kB] Get:8 disco-updates/universe amd64 amd64 18.09.7-0ubuntu1~18.04.5 [30.7 MB] Get:9 disco/main amd64 ubuntu-fan all 0.12.12 [34.6 kB] Fetched 52.5 MB in 4min 40s (188 kB/s) Preconfiguring packages ... Selecting previously unselected package pigz. (Reading database ... 67367 files and directories currently installed.) Preparing to unpack .../0-pigz_2.4-1_amd64.deb ... Unpacking pigz (2.4-1) ... Selecting previously unselected package bridge-utils. Preparing to unpack .../1-bridge-utils_1.6-2ubuntu1_amd64.deb ... Unpacking bridge-utils (1.6-2ubuntu1) ... Selecting previously unselected package cgroupfs-mount. Preparing to unpack .../2-cgroupfs-mount_1.4_all.deb ... Unpacking cgroupfs-mount (1.4) ... Selecting previously unselected package runc. Preparing to unpack .../3-runc_1.0.0~rc7+git20190403.029124da-0ubuntu1_amd64.deb ... Unpacking runc (1.0.0~rc7+git20190403.029124da-0ubuntu1) ... Selecting previously unselected package containerd. Preparing to unpack .../4-containerd_1.2.6-0ubuntu1_amd64.deb ... Unpacking containerd (1.2.6-0ubuntu1) ... Selecting previously unselected package dns-root-data. Preparing to unpack .../5-dns-root-data_2018091102_all.deb ... Unpacking dns-root-data (2018091102) ... Selecting previously unselected package dnsmasq-base. Preparing to unpack .../6-dnsmasq-base_2.80-1ubuntu1_amd64.deb ... Unpacking dnsmasq-base (2.80-1ubuntu1) ... Selecting previously unselected package Preparing to unpack .../7-docker.io_18.09.7-0ubuntu1~18.04.5_amd64.deb ... Unpacking (18.09.7-0ubuntu1~18.04.5) ... Selecting previously unselected package ubuntu-fan. Preparing to unpack .../8-ubuntu-fan_0.12.12_all.deb ... Unpacking ubuntu-fan (0.12.12) ... Setting up dnsmasq-base (2.80-1ubuntu1) ... Setting up runc (1.0.0~rc7+git20190403.029124da-0ubuntu1) ... Setting up dns-root-data (2018091102) ... Setting up bridge-utils (1.6-2ubuntu1) ... Setting up pigz (2.4-1) ... Setting up cgroupfs-mount (1.4) ... Setting up containerd (1.2.6-0ubuntu1) ... Created symlink /etc/systemd/system/ â /lib/systemd/system/containerd.service. Setting up ubuntu-fan (0.12.12) ... Created symlink /etc/systemd/system/ â /lib/systemd/system/ubuntu-fan.service. Setting up (18.09.7-0ubuntu1~18.04.5) ... Adding group `docker' (GID 115) ... Done. Created symlink /etc/systemd/system/ â /lib/systemd/system/docker.socket. Processing triggers for dbus (1.12.12-1ubuntu1.1) ... Processing triggers for systemd (240-6ubuntu5.8) ... Processing triggers for man-db (2.8.5-2) ...

    Enable and start Docker service.

    ahmer@docker-01:~$ sudo systemctl enable --now docker Synchronizing state of docker.service with SysV service script with /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable docker Created symlink /etc/systemd/system/ â /lib/systemd/system/docker.service.

    Verify Docker version.

    ahmer@docker-01:~$ docker --version Docker version 18.09.7, build 2d0083d


    Installing Docker Compose on Ubuntu Server 18.04 LTS:

    Compose (or Docker Compose) is a software tool to define and run multi-container Docker applications. Docker Compose uses a YAML file create, run and configure application services.

    We can install docker-compose on our preferred Linux distro using the same command.

    ahmer@docker-01:~$ sudo curl -L "$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose [sudo] password for ahmer: % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 617 100 617 0 0 696 0 --:--:-- --:--:-- --:--:-- 695 100 16.3M 100 16.3M 0 0 551k 0 0:00:30 0:00:30 --:--:-- 636k

    Grant execution permissions to all users on docker-compose executable.

    ahmer@docker-01:~$ sudo chmod +x /usr/local/bin/docker-compose

    Create a soft link to docker-compose command in common binary path, so the command can be accessible from any path.

    ahmer@docker-01:~$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

    Execute docker-compose command and check its version.

    ahmer@docker-01:~$ sudo docker-compose --version docker-compose version 1.25.4, build 8d51620a

    Docker Compose has been installed successfully on Ubuntu Server 18.04 LTS.


    Executing Basic Docker Commands on Ubuntu 18.04:

    Search for Alpine Linux in Docker online registry (Docker Hub).

    ahmer@docker-01:~$ sudo docker search alpine NAME DESCRIPTION STARS OFFICIAL AUTOMATED alpine A minimal Docker image based on Alpine Linux⦠6038 [OK] mhart/alpine-node Minimal Node.js built on Alpine Linux 453 anapsix/alpine-java Oracle Java 8 (and 7) with GLIBC 2.28 over A⦠439 [OK] frolvlad/alpine-glibc Alpine Docker image with glibc (~12MB) 231 [OK] gliderlabs/alpine Image based on Alpine Linux will help you wi⦠181 alpine/git A simple git container running in alpine li⦠113 [OK] mvertes/alpine-mongo light MongoDB container 108 [OK] yobasystems/alpine-mariadb MariaDB running on Alpine Linux [docker] [am⦠58 [OK] alpine/socat Run socat command in alpine container 45 [OK] kiasaki/alpine-postgres PostgreSQL docker image based on Alpine Linux 45 [OK] davidcaste/alpine-tomcat Apache Tomcat 7/8 using Oracle Java 7/8 with⦠40 [OK] zzrot/alpine-caddy Caddy Server Docker Container running on Alp⦠35 [OK] jfloff/alpine-python A small, more complete, Python Docker image ⦠33 [OK] easypi/alpine-arm AlpineLinux for RaspberryPi 32 byrnedo/alpine-curl Alpine linux with curl installed and set as ⦠28 [OK] hermsi/alpine-sshd Dockerize your OpenSSH-server with rsync and⦠27 [OK] etopian/alpine-php-wordpress Alpine WordPress Nginx PHP-FPM WP-CLI 23 [OK] hermsi/alpine-fpm-php Dockerize your FPM PHP 7.4 upon a lightweigh⦠22 [OK] zenika/alpine-chrome Chrome running in headless mode in a tiny Al⦠16 [OK] bashell/alpine-bash Alpine Linux with /bin/bash as a default she⦠14 [OK] davidcaste/alpine-java-unlimited-jce Oracle Java 8 (and 7) with GLIBC 2.21 over A⦠13 [OK] spotify/alpine Alpine image with `bash` and `curl`. 10 [OK] tenstartups/alpine Alpine linux base docker image with useful p⦠9 [OK] roribio16/alpine-sqs Dockerized ElasticMQ server + web UI over Al⦠7 [OK] cfmanteiga/alpine-bash-curl-jq Docker Alpine image with Bash, curl and jq p⦠5 [OK]

    Pull the image of Alpine Linux using docker command.

    ahmer@docker-01:~$ sudo docker pull alpine Using default tag: latest latest: Pulling from library/alpine c9b1b535fdd9: Pull complete Digest: sha256:ab00606a42621fb68f2ed6ad3c88be54397f981a7b70a79db3d1172b11c4367d Status: Downloaded newer image for alpine:latest

    List Docker images that are locally available on our Ubuntu 18.04 server.

    ahmer@docker-01:~$ sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE alpine latest e7d92cdc71fe 6 days ago 5.59MB

    Create a Docker container in interactive mode using Alpine Linux image and execute some test commands on it.

    ahmer@docker-01:~$ sudo docker run -it --rm alpine /bin/sh / # uname -a Linux 40c0683c7989 5.0.0-38-generic #41-Ubuntu SMP Tue Dec 3 00:27:35 UTC 2019 x86_64 Linux / # cat /etc/os-release NAME="Alpine Linux" ID=alpine VERSION_ID=3.11.3 PRETTY_NAME="Alpine Linux v3.11" HOME_URL="" BUG_REPORT_URL="" / # exit

    Create a Docker container in detach mode using Alpine Linux image.

    ahmer@docker-01:~$ sudo docker run -d alpine 0ad0a833a2b3e0e1c6a9735f27e8849786708d23f7c9070645d2c55650903c02

    Check list of recently executed containers.

    ahmer@docker-01:~$ sudo docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0ad0a833a2b3 alpine "/bin/sh" About a minute ago Exited (0) About a minute ago mystifying_blackburn

    Remove a Docker container.

    ahmer@docker-01:~$ sudo docker container rm 0ad0a833a2b3 0ad0a833a2b3

    Remove an image that is locally available on our Ubuntu 18.04 server.

    ahmer@docker-01:~$ sudo docker rmi alpine Untagged: alpine:latest Untagged: alpine@sha256:ab00606a42621fb68f2ed6ad3c88be54397f981a7b70a79db3d1172b11c4367d Deleted: sha256:e7d92cdc71feacf90708cb59182d0df1b911f8ae022d29e8e95d75ca6a99776a Deleted: sha256:5216338b40a7b96416b8b9858974bbe4acc3096ee60acbc4dfb1ee02aecceb10

    We have successfully installed Docker on Ubuntu 18.04 server and executed some basic commands thereon.  You should also read our guide on how to install Docker on CentOS 8.

    We have only performed the installation of Docker on Ubuntu 18.04 here, if you wish to learn more about containers then you should read Docker in Action by Manning Publications.

    No comments:

    Post a comment