Prerequisites
- A server running Ubuntu 22.04.
- A non-root user with
sudoprivileges.
Step 1: Update the System
Before installing Docker, it’s a good idea to update your package index and upgrade your installed packages. Open your terminal and run:
sudo apt update
sudo apt upgrade -y
Step 2: Install Required Packages
Docker requires a few prerequisite packages to be installed. Run the following command to install these:
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
Step 3: Add Docker’s Official GPG Key
Next, you need to add the official Docker GPG key to ensure the authenticity of the packages you download. Run:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Step 4: Add the Docker Repository
Now, add the Docker repository to your system:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Step 5: Update the Package Index Again
After adding the Docker repository, update your package index again:
sudo apt update
Step 6: Install Docker
Now, you can install Docker by running the following command:
sudo apt install docker-ce -y
Step 7: Start and Enable Docker
After the installation is complete, start the Docker service and enable it to run on boot:
sudo systemctl start docker
sudo systemctl enable docker
Step 8: Verify Docker Installation
To verify that Docker is installed correctly, run:
sudo docker --version
You should see the installed version of Docker.
Step 9: Manage Docker as a Non-root User (Optional)
If you want to run Docker commands without using sudo, you can add your user to the Docker group. Replace your-username with your actual username:
sudo usermod -aG docker your-username
After this, log out and back in for the changes to take effect. You can verify that you can run Docker without sudo by running:
docker run hello-world
Conclusion
You have successfully installed Docker on your Ubuntu 22.04 VPS. You can now start using Docker to manage containers.