How to Install Docker and Docker Compose on Ubuntu

Docker is a tool that lets you run applications in isolated containers. It simplifies project installation, migration, and scaling. In this guide, we'll cover how to install Docker and Docker Compose on an Ubuntu server.

Installing Docker

1. Update the package list:

sudo apt update Code language:  Bash  ( bash )

2. Install the packages required for the repository to work:

sudo apt install ca-certificates curl gnupg lsb-release -y Code language:  Bash  ( bash )

3. Add the Docker GPG key:

sudo mkdir -p /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg Code language:  Bash  ( bash )

4. Add 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 Code language:  Bash  ( bash )

5. Update the package list and install Docker:

sudo apt update sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y Code language:  Bash  ( bash )

Checking the Docker installation

Verify that Docker is installed and running:

sudo docker version Code language:  Bash  ( bash )

Test running the container:

sudo docker run hello-world Code language:  Bash  ( bash )

If you see the message "Hello from Docker!", then everything is working correctly.

Installing Docker Compose

the docker-compose binary separately from the built-in plugin, run the following commands:

1. Download the latest version:

sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose- $(uname -s) - $(uname -m) " -o /usr/ local /bin/docker-compose Code language:  Bash  ( bash )

2. Make the file executable:

sudo chmod +x /usr/ local /bin/docker-compose Code language:  Bash  ( bash )

3. Check the version:

docker-compose --version Code language:  Bash  ( bash )