Docker-wallpaper

Install Docker on Ubuntu 18.04

Introduction

Containers have really taken the IT industry by storm from personal usage to start-ups all the way up to enterprise. I have a few ideas for cool container-based tutorials so I thought the best place to start would be a simple tutorial on how to install Docker on Ubuntu 18.04.

I chose Ubuntu for this tutorial simply because anyone new to Linux will probably be using Ubuntu because of the community and because most things you google for usually bring up an Ubuntu Tutorial. I’m not going to dive too much into distribution selection but if you were wondering, that’s the reason.

Installation

To follow along you need to have a machine, virtual or physical running Ubuntu 18.04.

You can find a link to the installation iso over at the Ubuntu Website.

https://ubuntu.com/download/server

Once installed and you have logged into your fresh install of Ubuntu the first thing to do is install any updates that are available.

# Upgrade the Operating System.
sudo apt update && sudo apt upgrade -y

Once the updates have completed we need to make sure that there are no existing versions of Docker already installed by default.

# Remove any older versions.
sudo apt remove -y \
    docker \
    docker-engine \
    docker.io \
    containerd \
    runc

We are going to install Docker from the official Docker Repository. Before we can do that though we need to install some required tools to allow us to use a secure apt repository and the certificates required.

# Install support for apt repositories over https.
sudo apt install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common \

Now we have the tools to add the secure Docker Stable Repository we can go ahead and add it.

# Add Docker's official GPG Key.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# Verify the key with the fingerprint.
sudo apt-key fingerprint 0EBFCD88

# Add the Docker Stable Repository.
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(. /etc/os-release; echo "$UBUNTU_CODENAME") \
   stable"

Our server now has the Secure Ubuntu Docker Repository configured but the Apt Package Managed is not aware of the packages yet so we need to update the repository.

# Update the apt package index.
sudo apt-get update

Once complete, we can finally install the stable version of Docker.

# Install the latest version of Docker Engine Community.
sudo apt-get install -y \
    docker-ce \
    docker-ce-cli \
    containerd.io

Congratulations! At this point, you have an Ubuntu 18.04 running the latest stable version of Docker. The last thing we need to do is ensure that the Docker Services will start when the server boots.

# Configure Docker to start on boot.
sudo systemctl enable docker

Now that you have a server running Docker you can follow any docker guides or tutorials you like including the ones posted here.

You can test your installation by running the Docker Hello World Container.

# Test Docker Installation.
sudo docker run hello-world

More information about the Hello World Container can be found at the Docker Website.

https://hub.docker.com/_/hello-world

Docker Command as non-root User.

Before running the following on your system take note that this is not the best practice for a production server. For a development server, however, it allows you to run the docker command without the need for Sudo every time you need to update a container.

# Allow Docker to command to be used as a non-root user.
sudo groupadd docker
sudo usermod -aG docker ubuntu

# Activate the group changes.
newgrp docker

Summary

This is a minimal installation of Docker on Ubuntu 18.04 that will allow you to learn Docker.

If this post helped you or if you have spotted any mistake or improvement that could be made, be sure to let me know in the comments.

Leave a Reply

Your email address will not be published. Required fields are marked *

Close