Prerequisites
To follow this tutorial, you will need the following:
- One Ubuntu server. (You can follow the Ubuntu Server Initial Setup guide) including a sudo non-root user.
Installing Docker
We are going to install docker from the official Docker repository as the official Ubuntu repo might not be the latest version. To do that we need to add a new package source, add the GPG key from Docker to ensure the downloads are valid, and finally install Docker.
First, we will update our system:
Next, install a few prerequisite packages which let apt
use packages over HTTPS:
Then add the GPG key for the official Docker repository:
Now add the Docker repository to APT sources:
Update your existing list of packages again for the addition to be recognized:
Ensure you are installing from the Docker repo rather than the Ubuntu repo (Optional):
You’ll see output like this, although the exact version number may be different:
Notice docker-ce
is not installed, but the candidate for installation is from the official Docker repository.
Finally, install Docker:
Docker should now be installed, the daemon started, and the process enabled to start on boot. To verify it is running:
The output should be similar to the following:
Executing the Docker Command Without Sudo (Optional)
By default, the docker
command can only be run by the root user or by a user in the docker group. To avoid having to type sudo
every time you use the docker
command, add your username to the docker group and apply the new group membership:
If you need to add a user to the docker group that you’re not logged in as, declare the username explicitly using:
In conclusion, you’ve installed Docker on your Ubuntu server, enabling efficient application management with lightweight containers. Docker’s flexibility and scalability enhance productivity across various projects and tasks.