How to install Docker on Ubuntu Server 18

Share on Social Media

In this article, you will learn how to install Docker on Ubuntu server 18.04 LTS and execute some basic commands on that Containerization platform. #centlinux #ubuntu #docker

What is Docker?

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. It was initially developed in 2013 and now it is maintained by Docker, Inc.

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

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

Update Ubuntu Packages:

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

Update existing software packages by executing apt command.

$ sudo apt update

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

$ sudo apt upgrade

Install Docker on Ubuntu:

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

$ sudo apt install

Enable and start Docker service.

$ 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 version of installed Docker software.

$ docker --version
Docker version 18.09.7, build 2d0083d

Install Docker Compose on Ubuntu:

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

You can install docker-compose on your preferred Linux distro by using the following command.

$ sudo curl -L "$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  % 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.

$ 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 anywhere.

$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

Execute docker-compose command to check its version.

$ sudo docker-compose --version
docker-compose version 1.25.4, build 8d51620a

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

Execute Basic Docker Commands:

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

$ 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
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.

$ 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.

$ 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.

$ 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"
PRETTY_NAME="Alpine Linux v3.11"
/ # exit

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

$ sudo docker run -d alpine

Check list of recently executed containers.

$ 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 container as follows.

$ sudo docker container rm 0ad0a833a2b3

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

$ sudo docker rmi alpine
Untagged: alpine:latest
Untagged: alpine@sha256:ab00606a42621fb68f2ed6ad3c88be54397f981a7b70a79db3d1172b11c4367d
Deleted: sha256:e7d92cdc71feacf90708cb59182d0df1b911f8ae022d29e8e95d75ca6a99776a
Deleted: sha256:5216338b40a7b96416b8b9858974bbe4acc3096ee60acbc4dfb1ee02aecceb10

You 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.

Conclusion – Install Docker on Ubuntu:

In this article, you have learned how to install Docker on Ubuntu Server 18.04 LTS. If you wish to learn more about containers then you should read Docker in Action (PAID LINK) by Manning Publications.

Scroll to Top