Docker is a powerful platform that allows developers to create, deploy, and run applications in containers. This guide walks you through installing Docker on Ubuntu using Docker’s official repository, ensuring you get the latest version available.
Step 1: Update Your Package Repository
First, update the package list to ensure that you have the most up-to-date information about available software.
Step 1.1: Open Terminal
Press Ctrl + Alt + T
to open the terminal.
Step 1.2: Update the Package List
Run the following command to update your package list:
sudo apt update
Step 2: Install Prerequisite Packages
Docker requires certain packages to manage packages over HTTPS. Let’s install them now.
Step 2.1: Install Required Packages
Run the following command to install the necessary packages:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
Step 3: Add Docker’s Official GPG Key
Docker uses a GPG key for package verification. Let’s add that key to your system.
Step 3.1: Add Docker’s GPG Key
Run the following command to download and add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Step 4: Add Docker Repository
Now, add the Docker repository to your system’s list of APT sources.
Step 4.1: Set Up the Stable Repository
Add the official Docker repository for Ubuntu:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Step 5: Install Docker Engine
With the repository added, update your package list again and install Docker.
Step 5.1: Update Package List
Run this command to refresh your package list:
sudo apt update
Step 5.2: Install Docker
Install Docker by running:
sudo apt install docker-ce
This installs Docker Community Edition (CE), which is the version intended for most developers.
Step 6: Verify Installation
Let’s check if Docker was installed correctly and test it by running a container.
Step 6.1: Check Docker Service Status
To check if Docker is running, use the following command:
sudo systemctl status docker
If Docker is running, you should see an output indicating the service is active.
Step 6.2: Run a Test Container
Verify Docker by running the hello-world
container:
sudo docker run hello-world
This will pull the hello-world
image from Docker Hub and run it in a container, confirming that Docker is installed and working.
Step 7: Run Docker as a Non-root User (Optional)
By default, Docker commands require sudo
privileges. If you’d like to run Docker commands as a regular user, follow these steps:
Step 7.1: Create the Docker Group
Create a new group named docker
:
sudo groupadd docker
Step 7.2: Add Your User to the Docker Group
Add your current user to the docker
group:
sudo usermod -aG docker $USER
Step 7.3: Restart the Terminal
After adding your user to the docker
group, log out and log back in, or restart the terminal for the changes to take effect.
Conclusion
By following these steps, you have successfully installed Docker on your Ubuntu system. Now you’re ready to start containerizing your applications and exploring the powerful features Docker offers.
For more tutorials and guides on Docker, web development, and database management, visit CodeAllow.