Docker CE Installation Guide on Ubuntu Server 24.04 LTS
A detailed, step-by-step guide to installing Docker Engine on Ubuntu Server 24.04, covering prerequisites, repository setup, installation, and basic post-installation configuration.
Step 1: Update the System
Before installing Docker, it's a best practice to update your system's package index and upgrade existing packages to the latest versions.
sudo apt-get update && sudo apt-get upgrade -y
Step 2: Install Prerequisites
Install the necessary packages that allow `apt` to use a repository over HTTPS. This is required for adding Docker's official repository in the next step.
sudo apt-get install -y ca-certificates curl gnupg
Step 3: Add Docker’s Official GPG Key
Add Docker's official GPG key to verify the downloaded packages. This ensures the software is authentic and has not been tampered with.
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 Repository
Add the Docker repository to your list of sources. This will allow your system's package manager to find and download the Docker packages.
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu noble stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Step 5: Install Docker Engine
Now that the repository is set up, update your `apt` package index again and install the latest version of Docker Engine, CLI, and Containerd.
sudo apt-get update && sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Step 6: Verify the Installation
Verify that the Docker Engine is installed correctly by running the 'hello-world' container. This command downloads a test image and runs it in a container, confirming that everything works.
sudo docker run hello-world
Step 7: Manage Docker as a Non-Root User
By default, you need `sudo` to run Docker commands. To manage Docker as a non-root user, add your user to the `docker` group. Replace `your_user` with your actual username.
sudo usermod -aG docker $USER && newgrp docker
Step 8: Configure Docker to Start on Boot
The Docker service should be enabled to start automatically upon system boot. Use `systemctl` commands to ensure this behavior is configured correctly.
sudo systemctl enable docker.service && sudo systemctl enable containerd.service
Step 9: Install Docker Compose
Docker Compose is a tool for defining and running multi-container Docker applications. It is now part of the main Docker CLI but may need a symlink for older guides.
sudo apt install docker-compose-plugin -y && sudo ln -s /usr/libexec/docker/cli-plugins/docker-compose /usr/local/bin/docker-compose
Step 10: Final System Update
After all components are installed, a final system update and upgrade is recommended to ensure all packages and their dependencies are up to date.
sudo apt-get update && sudo apt-get upgrade -y