How to Install Docker and Docker Compose on Ubuntu - 2024

trueqap

trueqap

Posted on July 22, 2024

How to Install Docker and Docker Compose on Ubuntu - 2024

Docker is an open-source platform for developing, shipping, and running applications inside containers. Docker Compose simplifies the process of managing multiple Docker containers. This guide will help you install Docker and Docker Compose on an Ubuntu system step-by-step.

Table of Contents

  1. Update Package Repositories
  2. Install Docker Dependencies
  3. Add Docker GPG Key
  4. Set up the Docker Stable Repository
  5. Install Docker Engine
  6. Enable and Start Docker Service
  7. Verify Docker Installation
  8. Install Docker Compose
  9. Verify Docker Compose Installation

Prerequisites

  • Ubuntu 18.04 or later
  • A user with sudo privileges

Let's get started!

Step 1: Update Package Repositories

First, ensure your package repositories are up to date:

sudo apt update
Enter fullscreen mode Exit fullscreen mode

Step 2: Install Docker Dependencies

Next, install the necessary dependencies for Docker:

sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
Enter fullscreen mode Exit fullscreen mode

Step 3: Add Docker GPG Key

Add the official Docker GPG key to your system:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Enter fullscreen mode Exit fullscreen mode

Step 4: Set up the Docker Stable Repository

Set up the Docker stable repository on your system:

echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Enter fullscreen mode Exit fullscreen mode

Step 5: Install Docker Engine

Now, install Docker Engine, CLI, and containerd package:

sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io
Enter fullscreen mode Exit fullscreen mode

Step 6: Enable and Start Docker Service

Enable and start the Docker service to ensure it runs on system startup:

sudo systemctl enable docker
sudo systemctl start docker
Enter fullscreen mode Exit fullscreen mode

Step 7: Verify Docker Installation

Run a simple test to ensure Docker is installed and functioning correctly:

sudo docker run hello-world
Enter fullscreen mode Exit fullscreen mode

If everything is set up correctly, you’ll see a message indicating a successful installation.

Step 8: Install Docker Compose

Download the Docker Compose binary from the official GitHub repository:

sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Enter fullscreen mode Exit fullscreen mode

Apply executable permissions to the Docker Compose binary:

sudo chmod +x /usr/local/bin/docker-compose
Enter fullscreen mode Exit fullscreen mode

Create a symbolic link to ensure that docker-compose command can be run from any location:

sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
Enter fullscreen mode Exit fullscreen mode

Step 9: Verify Docker Compose Installation

Finally, verify that Docker Compose is installed correctly by checking its version:

docker-compose --version
Enter fullscreen mode Exit fullscreen mode

Conclusion

Congratulations! You have successfully installed Docker and Docker Compose on your Ubuntu system. You are now ready to start using Docker to containerize your applications and Docker Compose to manage multi-container applications. Happy coding!

💖 💪 🙅 🚩
trueqap
trueqap

Posted on July 22, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related