How to Install Docker on Ubuntu 22.04: A Complete Guide
Ready to harness the power of containerization? This comprehensive guide walks you through how to install Docker on Ubuntu 22.04 and start using it for efficient application deployment and management. Learn how to install, configure, and run your first container!
Why Use Docker on Ubuntu 22.04?
Docker simplifies application deployment by packaging applications and their dependencies into containers. Here are some key benefits of using Docker:
- Consistency: Ensures your application runs the same way across different environments, from development to production.
- Isolation: Isolates applications within containers, preventing conflicts and improving security.
- Efficiency: Optimizes resource utilization and reduces overhead compared to traditional virtual machines.
- Portability: Easily move containers between different hosts and cloud providers.
Step 1: Update Your Ubuntu System
Before installing Docker, it's crucial to update your system's package list. This ensures you're working with the latest versions and dependencies.
Step 2: Install Docker Prerequisites
Docker requires a few prerequisite packages to function correctly. Install these packages using the following command:
These packages enable APT to transfer files and data over HTTPS.
Step 3: Add the Official Docker GPG Key
Adding the GPG key ensures that the packages you download are valid and haven't been tampered with. curl
is utilized to download the GPG key from Docker's official website.
Step 4: Add the Docker Repository
Next, add the official Docker repository to your system's APT sources. This allows you to install Docker directly from Docker's repository.
Step 5: Install Docker Engine on Ubuntu
Now that you’ve added the Docker repository, update your package list again to include the new repository, use apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin
to install the packages.
Step 6: Verify Docker Installation
Time to confirm that Docker
is running. Use this command in the terminal to check information about Docker's installation and configuration.
A message confirming that the service is active and running verifies the accurate installation.
Step 7: Run Docker Without Sudo (Optional)
By default, you need sudo
to run Docker commands which is somewhat tedious. Avoid this by adding your user to the docker
group:
For the changes to take effect, log out and back in or run newgrp docker
. Now verify by running groups
.
Step 8: Test Docker: Run the Hello-World Image
Let's run a simple test image to verify your Docker installation.
If Docker is installed correctly, you'll see a message confirming everything is working.
Step 9: Basic Docker Commands
Now that Docker is installed, become familiar with these essential commands:
docker ps
: List running containers.docker images
: List downloaded images.docker pull image_name
: Download an image from Docker Hub.docker stop container_id
: Stop a running container.docker rm container_id
: Remove a stopped container.
Step 10: Explore Docker Compose for Multi-Container Applications
For more complex applications that involve multiple containers, check out Docker Compose. Docker Compose is an amazing tool for defining and running multi-container Docker applications. Using it, you can configure your application's services in a docker-compose.yml
file.