How to install docker on Ubuntu 18.04
This post will describe how to install docker on Ubuntu 18.04. It should be similar to other Ubuntu versions or Debian-based distributions. To install Docker, we’re going to use the Docker team’s DEB packages. You will need to be root (superuser) on the system to perform these operations, so remember to use sudo or get a root shell to run these commands.
First, we need to install some prerequisite packages.
Adding prerequisite Ubuntu packages
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
Then add the official Docker GPG key.
Adding the Docker GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
And then add the Docker APT repository. You may be prompted to confirm that you wish to add the repository and have the repository’s GPG key automatically added to your host.
Adding the Docker APT repository
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Now, we update our APT sources.
Updating APT sources
sudo apt-get update
We can now install the Docker package itself.
Installing the Docker packages on Ubuntu
sudo apt-get install docker-ce
This will install Docker and a number of additional required packages.
We should now be able to confirm that Docker is installed and running using the docker info command.
Checking Docker is installed on Ubuntu
sudo docker info
Docker and UFW
If you have UFW (Uncomplicated Firewall) installed on Ubuntu, then you’ll need to make a small change to get it to work with Docker.
You can check this running the following command:
sudo ufw status
If the output says “Status: inactive”, then you can skip the next steps. Otherwise, continue to enable packet forwarding.
Docker uses a network bridge to manage the networking on your containers. By default, UFW drops all forwarded packets. You’ll need to enable forwarding in UFW for Docker to function correctly. We can do this by editing the /etc/default/ufw file. Inside this file, change:
DEFAULT_FORWARD_POLICY="DROP"
To:
DEFAULT_FORWARD_POLICY="ACCEPT"
Save the update and reload UFW.
sudo ufw reload
That is all, now you have Docker installed on your Ubuntu system. It should be similar to other Debian based systems, but if you get stuck, get in touch.