Why Use Docker and How to Get Started on Ubuntu 24.04
In today's fast-paced development world, consistency and scalability are non-negotiable. Whether you're a solo developer or part of a DevOps team, managing dependencies, environments, and deployment across systems can get messy. That's where Docker comes in.
In this post, we'll explore why Docker is a game changer and walk through how to install and use Docker on Ubuntu 24.04.
What is Docker?
Docker is a platform that allows developers to package applications and their dependencies into containers. A container is a lightweight, standalone executable that includes everything needed to run a piece of software—code, libraries, system tools, and runtime.
Think of it as shipping your code in a box with everything it needs to run anywhere—without worrying about whether the host machine has the right Python version or the right PostgreSQL configuration.
Why Use Docker?
Docker has revolutionized software development and deployment by making applications easier to build, ship, and run consistently. Here are some key reasons to use Docker — illustrated with real-world examples:
1. Consistency Across Environments
Example: Imagine you're developing a web app on your laptop using Python 3.9 and a specific set of libraries. Your teammate's laptop has Python 3.8 and different library versions. When they run your app, it breaks due to version mismatches.
How Docker helps: You create a Docker container specifying the exact Python version and dependencies. When your teammate runs the container, they get the exact same environment, so the app behaves identically on both machines.
2. Simplified Dependency Management
Example: A developer works on two projects: one needs Node.js 14, the other Node.js 18. Installing both on the same machine can cause conflicts and headaches.
How Docker helps: Using separate containers for each project lets both Node versions run side-by-side without conflicts, since each container isolates its environment.
3. Portability and Flexibility
Example: Your company decides to move its application from a local data center to the cloud (AWS, Azure, or Google Cloud). Traditionally, this can require significant reconfiguration.
How Docker helps: Because your app is containerized, you can deploy the same Docker image across different platforms without changes, making migration smooth and reducing downtime.
4. Resource Efficiency and Speed
Example: Spin up multiple test environments for your application during development and QA phases. Traditional virtual machines consume a lot of resources and take minutes to boot.
How Docker helps: Containers share the host OS kernel and launch in seconds, allowing you to run many isolated environments simultaneously with minimal overhead.
5. Isolation and Security
Example: Your server runs multiple web services. If one crashes or is compromised, it shouldn't affect others.
How Docker helps: Containers isolate each service, so problems in one container don't impact others or the host system, improving reliability and security.
6. Microservices and Modern Architectures
Example: Netflix has broken down their massive monolithic app into hundreds of microservices, each deployed independently.
How Docker helps: Microservices run in separate containers, making it easier to update or scale individual components without affecting the whole system.
7. CI/CD and DevOps Integration
Example: A team uses Jenkins or GitHub Actions to automate testing and deployment. Running tests on inconsistent environments can cause failures unrelated to the code.
How Docker helps: Automated pipelines spin up containers with the exact environment every time, so tests are reliable and deployment is predictable.
8. Large Ecosystem and Community
Example: Instead of manually installing and configuring databases like MySQL or Redis, you can pull official Docker images and run them instantly.
How Docker helps: Developers save time and reduce errors by leveraging trusted, community-supported container images available on Docker Hub.
How to Install Docker on Ubuntu 24.04
There are two common ways to install Docker on Ubuntu 24.04: the simpler Ubuntu package method and the official Docker repository method. Choose based on your needs.
Option 1: Install Docker Using Ubuntu's Default Package (docker.io
)
This is the easiest way to get Docker running:
sudo apt update
sudo apt install -y docker.io
sudo systemctl start docker
sudo systemctl enable docker
Check installation with:
sudo docker run hello-world
Option 2: Install Docker Using the Official Docker Repository (Latest Version)
If you want the latest Docker features and tools, follow these steps:
Step 1: Update your system
sudo apt update
sudo apt upgrade -y
Step 2: Install prerequisite packages
sudo apt install -y ca-certificates curl gnupg
Step 3: Add Docker's official GPG key
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
Step 4: Set up the Docker repository
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Step 5: Install Docker Engine and related components
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Step 6: Verify Docker installation
sudo docker version
Run a test container:
sudo docker run hello-world
Your First Docker Container
Try running the hello-world container:
sudo docker run hello-world
If you see a success message, Docker is installed and working correctly!
Optional: Run Docker Without sudo
To avoid typing sudo
every time:
sudo usermod -aG docker $USER
newgrp docker
Test again:
docker run hello-world
Next Steps: Dockerize Your App
Once Docker is installed, you can:
- Create a
Dockerfile
to package your app - Use
docker-compose
for multi-container setups - Push your images to Docker Hub or private registries
Conclusion
Docker makes it easier to develop, ship, and run applications in a consistent and portable way. Whether you use the Ubuntu docker.io
package for simplicity or the official Docker repo for the latest features, Ubuntu 24.04 is a great environment to start your container journey.