Making Sense of The Infinite

Unlocking Infinite Possibilities Through Curiosity

Installing, Removing and Cleaning Up Docker on Ubuntu 24.04 LTS

Docker is an essential tool for modern developers, offering containerized solutions that streamline application deployment. This guide explains how to install, remove, and clean up Docker on Ubuntu 24.04 LTS. Follow these steps for a seamless experience.

Why Use Docker on Ubuntu 24.04 LTS?

Docker simplifies application deployment by bundling applications with their dependencies in isolated containers. Ubuntu 24.04 LTS, with its long-term support and robust performance, is an excellent choice for deploying Docker in production and development environments.

Key Benefits of Docker:

  • Portability: Applications run consistently across environments.
  • Efficiency: Reduces resource usage compared to virtual machines.
  • Scalability: Easily scale applications with container orchestration tools.

Installing Docker on Ubuntu 24.04 LTS

Step 1: Update Your System

Start by ensuring your system is up to date. Open a terminal and run:

sudo apt-get update
ShellScript

This updates the package index and ensures your system is ready for new installations.

Step 2: Install Required Packages

Docker requires some essential packages. Install them with:

sudo apt-get install -y ca-certificates curl
ShellScript

These tools help manage certificates and fetch files from the web.

Step 3: Add Docker’s GPG Key

To verify Docker packages, add their official GPG key:

sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
ShellScript

This step ensures secure downloads from Docker’s repository.

Step 4: Add the Docker Repository

Next, add Docker’s repository to your system’s package sources:

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
ShellScript

This command ensures access to Docker’s stable packages.

Step 5: Install Docker Packages

Finally, install Docker using the following command:

sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
ShellScript

This installs Docker and its essential components.

Removing Docker from Ubuntu 24.04 LTS

If you no longer need Docker, follow these steps to remove it completely from your system.

Step 1: Remove Docker Packages

Run the following command to remove Docker and related packages:

for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove -y $pkg; done
ShellScript

This removes any Docker-related software from your system.

Step 2: Purge Remaining Docker Files

To delete configuration files and additional components:

sudo apt-get purge -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
ShellScript

This ensures no residual files remain.

Step 3: Clean Up Docker Data

Delete Docker’s data directories with:

sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
ShellScript

These commands free up disk space by removing Docker’s storage.

Step 4: Remove Docker’s Repository and GPG Key

To prevent accidental reinstallation, remove Docker’s repository and GPG key:

sudo rm /etc/apt/sources.list.d/docker.list
sudo rm /etc/apt/keyrings/docker.asc
ShellScript

Step 5: Perform System Cleanup

Finally, clean up unnecessary packages and cached files:

sudo apt-get autoremove -y
sudo apt-get autoclean
ShellScript

This step tidies up your system after Docker removal.

Best Practices for Managing Docker

Regular Updates

Keeping Docker updated ensures security and access to the latest features. Run:

sudo apt-get update && sudo apt-get upgrade
ShellScript

Backup Configurations

Before removing Docker, back up your configurations to avoid losing valuable data.

Monitor Disk Usage

Docker containers and images can consume significant disk space. Regularly clean unused resources with:

docker system prune -a
ShellScript

Troubleshooting Common Issues

Installation Errors

If installation fails, check your internet connection and ensure your system is fully updated. Re-run the commands with root privileges.

Permission Denied Errors

Add your user to the docker group:

sudo usermod -aG docker $USER
ShellScript

Then log out and log back in.

Removing Stubborn Files

If Docker’s directories persist after removal, use:

sudo rm -rf /var/lib/docker
ShellScript

Conclusion

Docker on Ubuntu 24.04 LTS offers a powerful platform for application deployment. Installing and removing Docker is straightforward if you follow the steps outlined in this guide. Keeping your system clean and organized ensures optimal performance.

Last revised on

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *