how to Install Docker on Ubuntu
how to Install Docker on Ubuntu-In this guide, we will walk you through the process of installing Docker on Ubuntu 24.04 LTS. Docker is a powerful platform that allows developers and system administrators to build, ship, and run applications in containers. By the end of this tutorial, you will have a functional Docker installation and be ready to start using containers!
What is Docker?
Docker is an open-source platform that enables developers to automate the deployment of applications inside lightweight, portable containers. These containers package up the application code along with all its dependencies, ensuring that it runs consistently across different environments, from development to production.
Prerequisites
To follow along with this guide, ensure you have:
- An instance of Ubuntu 24.04 LTS installed.
- Access to a terminal with sudo privileges.
Step 1: Update Your System
Before installing Docker, it’s a good practice to update your system packages. Open your terminal and run the following command:
sudo apt update && sudo apt upgrade -y
This command updates the package lists and upgrades the installed packages to their latest versions.
Step 2: Uninstall Old Docker Versions (Optional)
If you have any older versions of Docker installed, it’s best to remove them. Run this command:
sudo apt remove docker docker-engine docker.io containerd runc
Step 3: Install Required Dependencies
Next, install the required dependencies for Docker:
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
Step 4: Add Docker’s Official GPG Key
To verify the integrity of the Docker packages, you need to add Docker’s GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Step 5: Set Up the Docker Repository
Add the Docker repository to your APT sources:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list - /dev/null
Step 6: Install Docker
Now you can install Docker. First, update your package list again:
sudo apt update
Then, install Docker:
sudo apt install docker-ce docker-ce-cli containerd.io -y
Step 7: Start Docker Service
Once installed, start the Docker service and enable it to run on boot:
sudo systemctl start docker
sudo systemctl enable docker
Step 8: Run Docker Without Sudo (Optional)
To run Docker commands without needing to prepend sudo, add your user to the Docker group:
sudo usermod -aG docker $USER
After running this command, log out and log back in for the changes to take effect.
Step 9: Verify Installation
To confirm that Docker has been installed correctly, check the Docker version:
docker --version
Step 10: Test Docker Installation
Run a simple test to ensure Docker is functioning correctly:
docker run hello-world
If Docker is set up correctly, you should see a message confirming that the Docker installation was successful:
Using Docker Hub
Once Docker is installed, you can start pulling images from Docker Hub. For example, to pull the PostgreSQL image, run:
docker pull postgres
Docker Hub is a cloud-based registry that allows you to share and manage your Docker images. You can create an account on Docker Hub to manage your images and repositories.
Step 11: Install Docker Desktop (Optional)
For users who prefer a graphical interface, Docker Desktop can be a great alternative to the command-line installation. To install Docker Desktop on Ubuntu 24.04 LTS, follow these steps:
- Visit the Docker Desktop page and download the appropriate Deb package for Ubuntu.
- Open a terminal, navigate to your Downloads folder, and install the downloaded package using the following command:
- After installation, you can launch Docker Desktop from your applications menu.
- Upon launching, you may be prompted to create a Docker account or sign in if you already have one. This is necessary to use Docker Hub for managing your images.
Docker Desktop provides a user-friendly interface for managing containers and images, along with additional features like Kubernetes integration and a simplified workflow for building and sharing applications.
Step | Command | Description |
---|---|---|
1 | sudo apt update && sudo apt upgrade -y | Update the package list and upgrade installed packages. |
2 | sudo apt remove docker docker-engine docker.io containerd runc | Remove any older versions of Docker. |
3 | sudo apt install apt-transport-https ca-certificates curl software-properties-common -y | Install dependencies required for Docker installation. |
4 | curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg | Add Docker’s official GPG key. |
5 | echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list - /dev/null | Set up the Docker repository. |
6 | sudo apt update | Update the package list again to include the Docker packages. |
7 | sudo apt install docker-ce docker-ce-cli containerd.io -y | Install Docker. |
8 | sudo systemctl start docker | Start the Docker service. |
9 | sudo systemctl enable docker | Enable Docker to start on boot. |
10 | sudo usermod -aG docker $USER | Add your user to the Docker group to run Docker without sudo. |
11 | docker --version | Verify the Docker installation by checking the version. |
12 | docker run hello-world | Run a test container to confirm Docker is working correctly. |
Conclusion
Congratulations! You have successfully installed Docker on your Ubuntu 24.04 LTS system. You can now start creating and managing containers for your applications. If you want to dive deeper into Docker’s capabilities, consider exploring Docker Compose and Docker Swarm for orchestration.
For more detailed information about Docker, check out the official documentation on Docker’s website.
FAQs
What are the prerequisites for installing Docker on Ubuntu 24.04 LTS?
To install Docker on Ubuntu 24.04 LTS, you need:
- An instance of Ubuntu 24.04 LTS installed.
- Access to a terminal with sudo privileges.
How can I verify if Docker has been installed correctly?
You can verify the installation by checking the Docker version. Run the following command:
docker --version
If installed correctly, this command will display the installed Docker version.
Can I run Docker commands without using ‘sudo’?
Yes, you can run Docker commands without ‘sudo’ by adding your user to the Docker group. Use the following command:
sudo usermod -aG docker $USER
After executing this command, log out and log back in for the changes to take effect.
What should I do if I have an older version of Docker installed?
If you have an older version of Docker, it’s recommended to remove it before installing the latest version. Use the following command:
sudo apt remove docker docker-engine docker.io containerd runc
Is Docker Desktop available for Ubuntu 24.04 LTS?
Yes, Docker Desktop is available for Ubuntu 24.04 LTS. You can download it from the Docker Desktop page and follow the installation instructions provided there.
For best Youtube service to grow faster vidiq:- Click Me
for best cheap but feature rich hosting hostingial:- Click Me
The best earn money ai tool gravity write:- Click Me
Use this tool to boost your website seo for free :- Click Me
Get Free Tools to Boost Productivity!
Explore our collection of free tools to help you work smarter and achieve more.
Access Free Tools