How to Install and Use Docker on Ubuntu 24.04
Docker is an open-source platform that automates the deployment, scaling, and management of applications. In this guide, we'll walk through the steps to install Docker on Ubuntu 24.04 and provide some basic commands to get you started.
Step 1: Update Your Operating System
First, ensure that your operating system is up to date. Open your terminal and run the following commands:
sudo apt update && sudo apt upgrade
This will update the package lists and install any available updates.
Step 2: Install Dependencies
Next, you'll need to install some necessary dependencies. Run the following command:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
These packages are required for adding repositories over HTTPS and managing software properties.
Step 3: Add Docker’s GPG Key
To ensure the authenticity of the Docker packages, add Docker’s GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
This command downloads and adds Docker’s GPG key to your system.
Step 4: Add Docker Repository
Add the Docker repository to APT sources:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
This adds the Docker repository to your APT sources list, enabling you to install Docker from Docker's official repository.
Step 5: Install Docker
Now, install Docker by running the following command:
sudo apt install docker-ce
After the installation is complete, verify that Docker is installed correctly by checking its version:
docker --version
You should see output similar to Docker version 20.10.8, build 3967b7d
.
Step 6: Test Docker
To ensure Docker is installed and working correctly, run a simple test container:
sudo docker run hello-world
This command downloads and runs the hello-world
Docker image, printing a message confirming that Docker is working correctly.
Step 7: Using the Docker Command
Here are some basic Docker commands to get you started:
List running containers:
sudo docker psList all containers (running and stopped):
sudo docker ps -aStart a container:
sudo docker start [container-ID | container-name]Stop a container:
sudo docker stop [container-ID | container-name]Remove a container:
sudo docker rm [container-ID | container-name]
Step 8: Run Docker Without Sudo
By default, Docker commands need to be run with sudo
. To run Docker as a non-root user, add your user to the Docker group:
sudo usermod -aG docker $USER
After running this command, log out and back in for the changes to take effect.
Conclusion
You've successfully installed Docker on Ubuntu 24.04 and learned some basic commands to manage Docker containers. Docker is a powerful tool that can streamline your development and deployment processes, and with these steps, you're well on your way to leveraging its full potential.