Update Software Repositories
sudo apt-get update
Install Docker on Ubuntu 18.04
sudo apt install docker.io
Start and Automate Docker
sudo systemctl start docker sudo systemctl enable docker docker --version
Prerequisites
It’s a good idea to update the local database of software to make sure you’ve got access to the latest revisions.
Open a terminal window and type:
sudo apt-get update
Allow the operation to complete.
Next, it’s recommended to uninstall any old Docker software before proceeding.
Use the command:
sudo apt-get remove docker docker-engine docker.io
To install Docker on Ubuntu, in the terminal window enter the command:
sudo apt install docker.io
The Docker service needs to be setup to run at startup. To do so, type in each command followed by enter:
sudo systemctl start docker
sudo systemctl enable docker
To verify the installed Docker version number, enter:
docker --version
Note: The official Docker website does not offer support for Ubuntu 18.04. It’s possible that the Ubuntu default repositories have not updated to the latest revision. There’s nothing wrong with running this installation. However, if you are up for a slightly more intensive operation, you can install a more recent (or specific) Docker from the official Docker repositories.
Update the local database with the command:
sudo apt-get update
You’ll need to run these commands to allow your operating system to access the Docker repositories over HTTPS.
In the terminal window, type:
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
To clarify, here’s a brief breakdown of each command:
The GPG key is a security feature.
To ensure that the software you’re installing is authentic, enter:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add –
To install the Docker repository, enter the command:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
The command “$(lsb_release –cs)” scans and returns the codename of your Ubuntu installation – in this case, Bionic. Also, the final word of the command – stable– is the type of Docker release.
A stable release is tested and confirmed to work, but updates are released less frequently. You may substitute edge if you’d like more frequent updates, at the cost of potential instability. There are other repositories, but they are riskier – more info can be found on the Docker web page. Step 5: Update Repositories
Update the repositories you just added:
sudo apt-get update
To install the latest version of docker:
sudo apt-get install docker-ce
List the available versions of Docker by entering the following in a terminal window:
apt-cache madison docker-ce
The system should return a list of available versions as in the image above.
At this point, type the command:
sudo apt-get install docker-ce=[version]
However, substitute [version]
for the version you want to install (pulled from the list you just generated).
For example:
You can also install Docker manually by downloading the Docker .deb file.
1. First, navigate to the Docker download page.
2. Next, click on the pool link, then stable, then amd64. This is the location of the stable Docker releases for Ubuntu 18.04.
3. Click on the Docker engine you want to install and the .deb package downloads automatically. Make a note of the path where you saved it.
4. To install Docker, run the following command (using the path of the downloaded Docker package):
sudo dpkg -i /path/to/docker.package.deb
Allow the installer to run.
For installing edge or testing versions of Docker, you can use convenience scripts.
This method should not be used in production environments or if you already have another version of Docker installed on your system.
Make sure to inspect the scripts before downloading and running them on your system.
To install the latest Docker engine, use the get.docker.com script by running the command:
curl -fsSL https://get.docker.com -o get-docker.sh
Run the script to start the installation:
sh get-docker.sh
The Docker service will start automatically.
Note: Using convenience scripts does not allow you to customize installation parameters or choose the Docker version.
To install the latest testing version of Docker, use the test.docker.com script:
curl -fsSL https://test.docker.com -o test-docker.sh
Start the installation by running the command:
sh test-docker.sh
Conclusion
Great job! You’ve got four (4) different options for installing Docker on Ubuntu 18.04.
Finally, you can check the Docker guides if you get into trouble, plus they have a fairly robust forum you can search. Happy developing!