Docker is an open-source platform that enables developers to build, deploy, and manage applications in lightweight, portable containers. It provides a way to package software along with all its dependencies (such as libraries, frameworks, and system tools) into a standardized unit called a container, ensuring that applications run consistently across different environments.
This guide will walk you through installing Docker on Ubuntu 24.04 and show you how to use Docker to manage containers effectively.
Prerequisites
Before proceeding, ensure that you have:
- A system running Ubuntu 24.04
- A user with sudo privileges
- An active internet connection
Step 1: Update Your System
Before installing Docker, it’s good practice to update your system packages to the latest versions.
sudo apt update && sudo apt upgrade -y
This command updates package lists and installs any pending upgrades.
Step 2: Install Required Dependencies
Docker requires certain packages to be installed first. Run the following command:
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
apt-transport-https
– Ensuresapt
can work with repositories over HTTPS.ca-certificates
– Provides trusted CA certificates for secure connections.curl
– A command-line tool to fetch data from URLs.software-properties-common
– Manages software sources.
Step 3: Add Docker’s Official GPG Key
To verify the authenticity of Docker packages, you need to add Docker’s official GPG key.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
This downloads and stores the GPG key securely.
Step 4: Add Docker Repository
Now, add the official Docker repository to the system.
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
This command ensures that you get the latest stable version of Docker.
Step 5: Install Docker
Update the package list and install Docker.
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io
docker-ce
– The Docker Community Edition (main package).docker-ce-cli
– Docker’s command-line interface.containerd.io
– Container runtime.
Step 6: Verify Docker Installation
To check if Docker is installed correctly, run:
docker --version
This should output the installed Docker version.
You can also verify that the Docker service is running:
sudo systemctl status docker
If it’s not running, start and enable Docker:
sudo systemctl start docker
sudo systemctl enable docker
Step 7: Add Your User to the Docker Group
By default, Docker commands require sudo privileges. To allow your user to run Docker without sudo
, add it to the docker group:
sudo usermod -aG docker $USER
After running this command, log out and log back in (or restart your system) to apply the changes.
Test it by running:
docker run hello-world
If everything is set up correctly, you should see a message confirming that Docker is working.
Step 8: Understanding Docker Commands
Now that Docker is installed, here are some basic commands to get you started.
1. Pull an Image
Docker images are pre-configured applications stored in Docker Hub.
Example: Pull the latest Ubuntu image.
docker pull ubuntu
2. Run a Container
Create and run a container from an image.
docker run -it ubuntu bash
This runs an Ubuntu container in interactive mode (-it
) with a Bash shell.
3. List Running Containers
To see active containers, use:
docker ps
To see all containers (including stopped ones):
docker ps -a
4. Stop a Container
To stop a running container:
docker stop <container_id>
Example:
docker stop 123456789abc
5. Remove a Container
To remove a stopped container:
docker rm <container_id>
To remove all stopped containers:
docker container prune
6. Remove an Image
To delete an image:
docker rmi <image_id>
Step 9: Using Docker Compose (Optional)
Docker Compose allows you to define and run multi-container applications.
1. Install Docker Compose
Run:
sudo apt install -y docker-compose
Verify installation:
docker-compose --version
2. Create a docker-compose.yml
File
Example: Running an NGINX web server.
Create a docker-compose.yml
file:
version: '3'
services:
web:
image: nginx:latest
ports:
- "8080:80"
3. Start the Service
Run:
docker-compose up -d
This starts the NGINX container and maps port 80 inside the container to port 8080 on your machine.
4. Stop the Service
Stop all running services:
docker-compose down
Step 10: Uninstall Docker (If Needed)
If you need to remove Docker, use:
sudo apt remove -y docker-ce docker-ce-cli containerd.io<br>sudo rm -rf /var/lib/docker
This will completely remove Docker and its data.
Conclusion
You have successfully installed Docker on Ubuntu 24.04! You also learned how to:
- Run and manage Docker containers
- Pull images from Docker Hub
- Use
docker-compose
for multi-container applications
Now you can start containerizing your applications efficiently. 🚀
Would you like additional examples or troubleshooting tips?
- Roblox Force Trello - February 25, 2025
- 20 Best Unblocked Games in 2025 - February 25, 2025
- How to Use Java Records to Model Immutable Data - February 20, 2025