- Published on
How to deploy Docker containers on Ubuntu 24.04
- Authors
- Name
- Marcio Moreira Junior
Are you ready to streamline your application deployment process? Docker has become a cornerstone of effective DevOps strategies, enabling developers to package applications in lightweight containers. With Ubuntu 24.04 being a popular choice for server environments, understanding how to deploy Docker containers on this platform is essential for modern application development and deployment. In this guide, we will walk you through the steps necessary to install Docker, create and run containers, manage images, and troubleshoot common issues.
Prerequisites for Installing Docker on Ubuntu 24.04
Before you dive into deploying Docker containers, ensure you have the following prerequisites:
- Ubuntu 24.04 installed: This guide assumes you are using the latest version of Ubuntu. Ensure your system is updated:Expected output:
sudo apt update && sudo apt upgrade -y
[...] Packages are listed by name to be upgraded 0 installed, 0 upgraded, 0 to remove and 0 not upgraded.
- Root or sudo access: You will need administrative privileges to install Docker.
- A basic understanding of terminal commands: You should be comfortable using the command line interface.
Installing Docker Engine
To deploy Docker containers, first, you'll need to install Docker Engine. Here are the steps:
- Install required packages: This will allow apt to use packages over HTTPS:
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
- Add Docker's official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- Set up the stable repository:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- Install Docker Engine:
sudo apt update sudo apt install docker-ce -y
- Verify that Docker is running:Expected output should show that the Docker service is active and running.
sudo systemctl start docker sudo systemctl enable docker sudo systemctl status docker
Running Your First Docker Container
Now that Docker is installed, let's deploy your first container. We'll use the hello-world image as a quick test:
- Pull the hello-world image:
sudo docker pull hello-world
- Run the hello-world container:Expected output:
sudo docker run hello-world
Hello from Docker! This message shows that your installation appears to be working correctly.
Managing Docker Containers
Once your first container is up and running, understanding how to manage your Docker containers is crucial:
List running containers:
sudo docker ps
This command displays the currently running containers with their status.
List all containers (including stopped):
sudo docker ps -a
Stopping a running container:
sudo docker stop <container_id>
Replace
<container_id>
with the actual container ID or name.Removing a container:
sudo docker rm <container_id>
Troubleshooting Common Issues
During your Docker journey, you may encounter various issues. Here are some common problems and their solutions:
Docker daemon not starting: If the Docker daemon does not start, check logs for errors using:
sudo journalctl -u docker.service
Permission denied errors: If you get permission denied errors when running Docker commands, consider adding your user to the Docker group:
sudo usermod -aG docker $USER
Log out and back in for the changes to take effect.
Container not running: If your container exits immediately, check its logs for errors:
sudo docker logs <container_id>
Conclusion
Deploying Docker containers on Ubuntu 24.04 is straightforward if you follow these structured steps. By mastering Docker, you set the groundwork for efficient, scalable application deployment patterns. Whether you're a seasoned DevOps professional or a beginner, Docker provides powerful tools to enhance your workflows. Dive into the world of containerization, and unlock the potential of your applications today!