How to Install Docker on Ubuntu 18.04
In this article, we demonstrate how to install Docker on Ubuntu 18.04 and review some basic Docker commands.
Join the DZone community and get the full member experience.Join For Free
In this article, you’ll install and use Docker Community Edition (CE) on Ubuntu 18.04.
- Ubuntu 18.04 64-bit operating system.
- A user account with sudo privileges
The Docker installation package available in the official Ubuntu repository may not be the latest version. To ensure we get the latest version, we’ll install Docker from the official Docker repository. To do that, we’ll add a new package source, add the GPG key from Docker to ensure the downloads are valid, and then install the package.
It’s a good idea to update the local database of software to make sure you’ve got access to the latest revisions
Update your existing list of packages by typing:
Next, install a few prerequisite packages which let apt use packages over HTTPS:
Then add the GPG key for the official Docker repository to your system:
Add the Docker repository to APT sources:
Next, update the package database with the Docker packages from the newly added repo:
Make sure you are about to install from the Docker repo instead of the default Ubuntu repo:
You’ll see output like this:
Notice that docker-ce is not installed, but the candidate for installation is from the Docker repository for Ubuntu 18.04 (bionic).
Finally, install Docker:
Docker should now be installed, the daemon started, and the process enabled to start on boot. Check that it’s running:
The output should be similar to the following, showing that the service is active and running:
Add Your User to Docker Group
By default, the Docker command can only be run the root user. If you attempt to run the Docker command without adding a user to the Docker group, you’ll get an output like this:
If you want to avoid the above error, add your username to the Docker group:
To apply for the new group membership, log out of the server, and log in. To confirm that your user is added to the Docker group by typing:
Let’s explore the Docker commands.
Docker Command Syntax
Docker consists of options followed by the command.
Usage: docker [OPTIONS] COMMAND
In this article, you installed Docker on Ubuntu. In the next article, we talk about basic Docker commands and usage.
Published at DZone with permission of Krishna Prasad Kalakodimi. See the original article here.
Opinions expressed by DZone contributors are their own.