How to Install Docker on Ubuntu 18.04?

Photo of author

By admin

If you’re a part of the ever-growing IT realm, you must have heard words like containerization and Docker. It’s a known fact that many IT personnel have begun opting for Docker today. Docker is an awesome tool for developing, deploying and managing apps with ease. In fact, it makes the bothersome process of container deployment pretty effortless. Many industry biggies like Spotify, ING, The New York Times, PayPal, The Washington Post, and many others, have embraced Docker wholeheartedly because of the increased convenience it offers. You, too, can install Docker on Ubuntu 18.04 for personal use. Fret not if you aren’t informed about the installation steps. This tutorial seeks to handle that aspect. Read on.

Why Install Docker on Ubuntu 18.04?

Now, you might be pondering about the need for installing Docker on your Ubuntu PC. Well, here are some of Docker’s amazingly cool features. Check them out:

  • Return on Investment (ROI) is perhaps its foremost feature. This leads to Docker being capable of cutting costs and efficiently boosting profits. All companies strive to generate steady profits over a long period. Docker can be their solution in this regard.
  • Docker makes its users capable of constructing a container image (CI) and utilizing it anywhere and anytime during the deployment process. Thus, it enables users to isolate non-dependent steps and execute them side by side.
  • Another great feature of Docker is its facility of rapid deployment. It can reduce the deployment time drastically. This happens because Docker tends to generate a spate container for each process and ditches OS boots. Hence, one can build or demolish info without the fear of reintroducing it at a greater cost than what’s considered reasonable.
  • Docker supports multiple platforms. Such multi-platform support leads to increased portability. Users can run Docker containers on Rackspace, Amazon (ECC) Elastic Cloud Computing, DigitalOcean, Google Compute Engine, Microsoft Azure, and many others. So, a container running on one platform can be ported to another. For instance, one could port a container running on Rackspace to Amazon ECC and vice-versa.

Steps to Install Docker on Ubuntu 18.04

Now, let’s focus on our foremost concern, that is, installing Docker on our Ubuntu 18.04 computer. Here we’re taking Docker Community Edition. But first, we need to accomplish a few prerequisites.


  • A Ubuntu 18.04-installed server
  • A valid Docker Hub account

Step 1. Install Docker CE

While installing the Docker software, many people’s first instinct is to install it from the official Ubuntu repository. But we suggest you ditch that practice. Why? Because most of the time, the Docker installation package you get from there wouldn’t be the latest edition. So to make sure your Docker software is the latest, you have to install it from the Docker repository. For that purpose, you must attach a new package source and verify the validity of downloads by attaching a GPG key from Docker. Only after that should you proceed to install it.

So, first, you got to update your current package list:

sudo apt update

Next, install a few essential packages which will allow apt employ packages on HTTPS:

sudo apt install apt-transport-https ca-certificates curl software-properties-common

Then, you have to attach the GPG key we talked about earlier to the Docker repository:

curl -fsSL | sudo apt-key add –

Now, attach the Docker repository to apt sources:

sudo add-apt-repository “deb [arch=amd64] bionic stable”

After doing so, you need to update the package DB from the repository you just attached:

sudo apt update

Like we said earlier, ensure the successful installation of packages from the Docker repository instead of the official Ubuntu repository:

apt-cache policy docker-ce

Once finished, you should see an output as given below:


Installed: (none)

Candidate: 18.03.1~ce~3-0~ubuntu

Version table:

18.03.1~ce~3-0~ubuntu 500

500 bionic/stable amd64 Packages

Here, you’d find the Docker CE file isn’t installed yet. It’s a confirmation of the fact that the installation contender comes from the Docker repository.

Now, you got to install the Docker CE file:

sudo apt install docker-ce

It will install Docker CE on your local machine with daemon enabled. Also, the service will now start with each reboot. You may verify its status by executing this command:

sudo systemctl status docker

If everything is fine, you will receive this output stating that the service is up and running:

docker.service – Docker Application Container Engine

Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)

Active: active (running) since Thu 2018-07-05 15:08:39 UTC; 2min 55s ago


Main PID: 10096 (dockerd)

Tasks: 16

CGroup: /system.slice/docker.service

├─10096 /usr/bin/dockerd -H fd://

└─10113 docker-containerd –config /var/run/docker/containerd/ ml

Now that you’ve installed Docker, you get both the daemon as well as the Docker client. Later in this tutorial, we will teach you about utilizing this command. For now, proceed to the next step.

Step 2 (optional). Execute the Docker Command Minus the sudo

Typically, one can run the docker command only if they possess root access or are a part of the docker group. This group gets constructed while you’re installing the Docker tool. Now, in case you try to run this docker command without fulfilling either of these two conditions, you’re bound to receive an output like this:

docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?.

See ‘docker run –help’.

So what to do? Well, to ditch the need of typing sudo every time you attempt at running the docker command, execute the below-given command to specify your username to your docker group:

sudo usermod -aG docker ${USER}

To finalize your group initiation process, you got to sign out of your server and run this command:

su – ${USER}

After doing that, you’d be asked to provide your user password before you can proceed further.

You need to authenticate the addition of your user to the docker group. For doing so, use this command:

id -nG

Suppose you plan on adding a user to your Docker group that’s not a part of it. Then, you got to define the concerned username using the below command:

sudo usermod -aG docker username

We will proceed, presuming that you’re running the docker command as a Docker group member from now on.

So, that being said, let us now delve deep into the docker command.

Step 3. Utilize the Docker Command

The docker command utilization comprises a series of commands, options, and arguments. The syntax could usually be found in the following form:

sudo usermod -aG docker username

By utilizing the command below, you can see all your accessible subcommands:


As of now, the list of available subcommands is as follows:

attach Attach local standard input, output, and error streams to a running container

build Build an image from a Dockerfile

commit Create a new image from a container’s changes

cp Copy files/folders between a container and the local filesystem

create Create a new container

diff Inspect changes to files or directories on a container’s filesystem

events Get real time events from the server

exec Run a command in a running container

export Export a container’s filesystem as a tar archive

history Show the history of an image

images List images

import Import the contents from a tarball to create a filesystem image

info Display system-wide information

inspect Return low-level information on Docker objects

kill Kill one or more running containers

load Load an image from a tar archive or STDIN

login Log in to a Docker registry

logout Log out from a Docker registry

logs Fetch the logs of a container

pause Pause all processes within one or more containers

port List port mappings or a specific mapping for the container

ps List containers

pull Pull an image or a repository from a registry

push Push an image or a repository to a registry

rename Rename a container

restart Restart one or more containers

rm Remove one or more containers

rmi Remove one or more images

run Run a command in a new container

save Save one or more images to a tar archive (streamed to STDOUT by default)

search Search the Docker Hub for images

start Start one or more stopped containers

stats Display a live stream of container(s) resource usage statistics

stop Stop one or more running containers

tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE

top Display the running processes of a container

unpause Unpause all processes within one or more containers

update Update configuration of one or more containers

version Show the Docker version information

wait Block until one or more containers stop, then print their exit codes

Now, if you wish to see the options obtainable on a particular subcommand, utilize this:

docker docker-subcommand –help

You are also capable of viewing your Docker’s system info by simply typing this command:

docker info

Let us focus on some of these subcommands. We will utilize Docker images first.

Step 4. Begin Working with Docker Images

Docker images are essential for constructing Docker containers. Typically, Docker gathers all these images from the cloud-based repository Docker Hub, which is managed by Docker. Everybody is capable of hosting their images on this repository. Therefore, the chance is always high that you’d find the images of all your necessary apps and Linux distributions on Docker Hub.

To ensure your eligibility to navigate to Docker Hub and download your required images, utilize this command below:

docker run hello-world

If your eligibility status is positive, you will get an output like this:

Unable to find image ‘hello-world:latest’ locally

latest: Pulling from library/hello-world

9bb5a5d4561a: Pull complete

Digest: sha256:3e1764d0f546ceac4565547df2ac4907fe46f007ea229fd7ef2718514bcec35d

Status: Downloaded newer image for hello-world:latest

Hello from Docker!

This message shows that your installation appears to be working correctly.

Originally, Docker couldn’t find the hello-world image in your local storage. Therefore, it downloaded that image. After the completion of the download, Docker built a new container utilizing the newly downloaded image. It also constructed the app inside that container. Hence, the message.

You can look for the images you need utilizing the docker command + search subcommand. For instance, execute the following command if you’re trying to find the Ubuntu image:

docker search ubuntu

Doing so will take the script to Docker Hub and show all the available image names matching the search string. So, you will receive the below output:


ubuntu Ubuntu is a Debian-based Linux operating sys… 7917 [OK]

dorowu/ubuntu-desktop-lxde-vnc Ubuntu with openssh-server and NoVNC 193 [OK]

rastasheep/ubuntu-sshd Dockerized SSH service, built on top of offi… 156 [OK]

ansible/ubuntu14.04-ansible Ubuntu 14.04 LTS with ansible 93 [OK]

ubuntu-upstart Upstart is an event-based replacement for th… 87 [OK]

neurodebian NeuroDebian provides neuroscience research s… 50 [OK]

ubuntu-debootstrap debootstrap –variant=minbase –components=m… 38 [OK]

1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 36 [OK]

nuagebec/ubuntu Simple always updated Ubuntu docker images w… 23 [OK]

tutum/ubuntu Simple Ubuntu docker images with SSH access 18

i386/ubuntu Ubuntu is a Debian-based Linux operating sys… 13

ppc64le/ubuntu Ubuntu is a Debian-based Linux operating sys… 12

1and1internet/ubuntu-16-apache-php-7.0 ubuntu-16-apache-php-7.0 10 [OK]

1and1internet/ubuntu-16-nginx-php-phpmyadmin-mariadb-10 ubuntu-16-nginx-php-phpmyadmin-mariadb-10 6 [OK]

eclipse/ubuntu_jdk8 Ubuntu, JDK8, Maven 3, git, curl, nmap, mc, … 6 [OK]

codenvy/ubuntu_jdk8 Ubuntu, JDK8, Maven 3, git, curl, nmap, mc, … 4 [OK]

darksheer/ubuntu Base Ubuntu Image — Updated hourly 4 [OK]

1and1internet/ubuntu-16-apache ubuntu-16-apache 3 [OK]

1and1internet/ubuntu-16-nginx-php-5.6-wordpress-4 ubuntu-16-nginx-php-5.6-wordpress-4 3 [OK]

1and1internet/ubuntu-16-sshd ubuntu-16-sshd 1 [OK]

pivotaldata/ubuntu A quick freshening-up of the base Ubuntu doc… 1

1and1internet/ubuntu-16-healthcheck ubuntu-16-healthcheck 0 [OK]

pivotaldata/ubuntu-gpdb-dev Ubuntu images for GPDB development 0

smartentry/ubuntu ubuntu with smartentry 0 [OK]


Notice the output carefully. The “[OK]”s in the “OFFICIAL” section of the output signifies images that the organization behind the project made and endorsed. Once you’re finished picking the image of your preference, utilize the pull subcommand for downloading it to your PC.

Thus, you can run the following command for downloading the Ubuntu image:

docker pull ubuntu

Once downloaded, you will get the following output:

Using default tag: latest

latest: Pulling from library/ubuntu

6b98dfc16071: Pull complete

4001a1209541: Pull complete

6319fc68c576: Pull complete

b24603670dc3: Pull complete

97f170c87c6f: Pull complete

Digest: sha256:5f4bdc3467537cbbe563e80db2c3ec95d548a9145d64453b06939c4592d67b6d

Status: Downloaded newer image for ubuntu:latest

After downloading an image, you are free to execute the run subcommand for creating a container from your downloaded image. As the hello-world instance might’ve made you comprehend, if an image download fails to occur even after executing the docker command + run subcommand, the Docker client will initially download that image. And, after that, it will create a container utilizing the same.

Your downloaded images could be viewed by executing this simple command:

docker images

The output you will get should something like this:


ubuntu latest 113a43faa138 4 weeks ago 81.2MB

hello-world latest e38bc07ac18e 2 months ago 1.85kB

In case you didn’t know, you can modify the images you utilize for the container running. Also, it’s possible to use them for constructing new images, capable of being uploaded to Docker Hub or other similar repositories whenever you please.

So, the next step will dig deeper into this container running matter.

Step 5. Run a Docker Container

Remember the hello-world container you executed earlier? That was a perfect instance of a container that is capable of running and exiting after releasing a demo text. Containers, as you may know, have many other usages. Such a fact shouldn’t come as a surprise as they’re pretty much like VMs, albeit with increased resource-friendliness.

For instance, run a container utilizing the newest Ubuntu image. The below command could give you interactive shell access:

docker run -it ubuntu

Next, try to reflect in your command the fact that your work is occurring within that container. Therefore, make it look something like this:


Notice the container ID here. Remember it because we will need it later for container identification provided that you’ve decided to delete it.

With that, you’ve now become capable of running any command you wish to within your container. Let us take the task of package DB update inside the container as an instance. As you are a root user within your container, you don’t have to type sudo before your command:


After that, install any app of your preference inside it. For now, we will be installing Node.js:


Doing so will help install Node.js in your container. After the installation process is over, you got to verify Node.js’s installation with this command:


The output you will get from here will state the version of your newly installed Node.js:


Remember that anything you modify inside the container applies to that container only.

Now enter exit in the command-line to exit your container.

Step 6: Manage Docker Containers

This step is about the container management aspect. After you install Docker on Ubuntu 18.04 and use it for a while, you’ll find tons of both active and inactive containers stowed on your PC. You can view the active containers list using the command given below:

docker ps

After doing so, you will get the below output:


You have begun two containers till now from the hello-world and Ubuntu images. While they are in an active state at present, they still occupy some space in your PC.

You can also view both the active and inactive container list at once by executing the following command:

docker ps -a

You will ten to one receive the below output:

d9b100f2f636 ubuntu “/bin/bash” About an hour ago Exited (0) 8 minutes ago sharp_volhard

01c950718166 hello-world “/hello” About an hour ago Exited (0) About an hour ago festive_williams

Executing the below command will permit you to view your most recent container:

docker ps -l


d9b100f2f636 ubuntu “/bin/bash” About an hour ago Exited (0) 10 minutes ago sharp_volhard

You can restart a container that has stopped by implementing docker start and then, your docker ID. Here we will use a Ubuntu-based container:

docker start d9b100f2f636

Once the container gets started, you can check its status by using docker ps:


d9b100f2f636 ubuntu “/bin/bash” About an hour ago Up 8 seconds sharp_volhard

Now, if you want to stop a container from running, you have to implement docker stop and then, the container ID. Here, we will opt for the Docker-provided container name, that is, sharp_volhard:

docker stop sharp_volhard

If you ever feel that you no longer need any particular container, you can eliminate its existence simply by utilizing the docker rm + container ID combo. Suppose you don’t know the hello-world-related container name, you can use docker ps. This command will aid you in finding the container ID you’re looking for:

docker rm festive_williams

The –name switch can be utilized in initializing and naming a container. Also, there is the –rm switch for generating a self-removing container upon stoppage. For further info regarding these options and facilities, you may run the docker run help command.

You can turn your containers into images. These images can then be utilized for creating new containers.

Step 7. Make Modifications in a Container to a Docker image

While dealing with a Docker machine, you are capable of generating, changing, or removing files exactly like a VM. Any modification you make will only be confined to that container. You are free to initialize or eliminate it. But if you utilize the docker rm command, you won’t be able to recover them.

Once you install Node.js within your Ubuntu container, you possess a running container using an image. However, the created container and the source image are different. But you can base new images on this Node.js container afterward.

Next, modify a new Docker image using the following command:

docker commit -m “What you did to the image” -a “Author Name” container_id repository/new_image_name

The command specifies both the changes you committed as well as the ID of the author. Do you remember the Container ID you came across during the initial stages of your Docker session? Unless you made extra repositories to the Docker Hub, your username is your repository. Here’s how the command will be like:

docker commit -m “added Node.js” -a “sammy” d9b100f2f636 sammy/ubuntu-nodejs

Once you implement an image, that image gets stowed in your local machine.

Using the below command again to list images will help you view both the latest image as well as the source it came from:

docker images

The output you receive would be like this:


sammy/ubuntu-nodejs latest 7c1f35226ca6 7 seconds ago 179MB

ubuntu latest 113a43faa138 4 weeks ago 81.2MB

hello-world latest e38bc07ac18e 2 months ago 1.85kB

In the above instance, the latest image is labeled as “ubuntu-nodejs” that came from the source Ubuntu image. There is also a noticeable difference between their size that is a sure shot indicator of the modifications. This instance reflects the addition of Node.js installation as a change.

You can also construct an image from the Docker file. It allows you to auto-install software in a new image. However, it isn’t really our focus here.

Step 8. Route Docker Images to a Docker Repository

The last thing you have to get done is to create an unhackneyed image from an already extant one and share it with others. These include a select few of your buddies, on Docker Hub, or some other Docker repository accessible to you.

Utilize the below command to sign in to your Docker Hub account:

docker login -u docker-registry-username

Next, enter your Docker Hub when asked. If entered right, your sign-in would be triumphant.

In case your Docker repository username and the name you utilized while generating the image differ, make things right by tagging your repository username with your image. Execute this command:

docker tag sammy/ubuntu-nodejs docker-registry-username/ubuntu-nodejs

After doing so, you may start routing your image:

docker push docker-registry-username/docker-image-name

For routing the ubuntu-nodejs to your repository, type:

docker push sammy/ubuntu-nodejs

If successful, an output would state that clearly:

The push refers to a repository []

e3fbbfb44187: Pushed

5f70bf18a086: Pushed

a3b5c80a4eba: Pushed

7f18b442972b: Pushed

3ce512daaf78: Pushed

7aae4540b42d: Pushed

Also, you would be able to see that image name on your dashboard.

Nonetheless, if the received output looks like the following one, maybe you didn’t sign in:

The push refers to a repository []

e3fbbfb44187: Preparing

5f70bf18a086: Preparing

a3b5c80a4eba: Preparing

7f18b442972b: Preparing

3ce512daaf78: Preparing

7aae4540b42d: Waiting

unauthorized: authentication required

In that case, utilize docker login and perform the procedure again. Then, navigate to your Docker Hub registry page’s dashboard and see whether the image name appears there or not.

And that’s all. Your quest to install Docker on Ubuntu 18.04 is over.


To conclude, the Docker tool is capable of resolving a very common issue of deploying containers or containerized apps that is rampant among almost all IT people. Docker could be a great lifesaver to you if you struggle with a container or containerized app deployment too. Being pretty much a VM, you can run any image you please using this wonderful software. The best thing about Docker is perhaps its open-source facilities that make way for continual updates and constant improvements by an amazingly dedicated community.

Also, as you can see from the entire article, you can install Docker on Ubuntu 18.04 with ease. The procedure is pretty simple. However, losing track of the to-be-followed steps mentioned above could ball things up badly. That’s why it’s crucial to go through the tutorial religiously and then, execute each step with utmost care. From installing the Docker Community Edition software to routing Docker images to a Docker repository – only the proper execution of every step could guarantee the success of their Docker installation. Now that you comprehend what to do and how to do so, you can install Docker on your Ubuntu-installed PC with ease. All the best for testing your knowledge.

Leave a Comment