Installing Docker Engine and Docker Compose

  • avatar
  • 1.9K Views
  • 3 mins read

Docker is a service that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels. Because all of the containers share the services of a single operating system kernel, they use fewer resources than virtual machines.

Prerequisites

Enable virtualization on the computer bios (usually it's already enabled).

Set up the repository

Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker repository. Afterward, you can install and update Docker from the repository.

  1. Update the apt package index and install packages to allow apt to use a repository over HTTPS:

    sudo apt-get update && sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release
  2. Add Docker’s official GPG key:

    curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  3. Use the following command to set up the stable repository:

    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

Install Docker Engine

  1. Update the apt package index and install the latest version of Docker Engine and containerd:

    sudo apt-get update && sudo apt-get install docker-ce docker-ce-cli containerd.io
  2. Verify that Docker Engine is installed correctly by running the hello-world image:

    sudo docker run hello-world

Manage Docker as a non-root user

The Docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can only access it using sudo. The Docker daemon always runs as the root user.

If you don’t want to preface the docker command with sudo, create a Unix group called docker and add users to it. When the Docker daemon starts, it creates a Unix socket accessible by members of the docker group.

To create the docker group and add your user:

  1. Create the docker group:

    sudo groupadd docker
  2. Add your user to the docker group:

    sudo usermod -aG docker $USER
  3. Log out and log back in so that your group membership is re-evaluated (sometimes restart is required).

  4. Verify that you can run docker commands without sudo:

    docker run hello-world

    This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.

Install Docker Compose

On Linux, you can download the Docker Compose binary from the Compose repository release page on GitHub. Follow the instructions from the link, which involve running the curl command in your terminal to download the binaries. These step-by-step instructions are also included below.

  1. Run this command to download the current stable release of Docker Compose:

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

    To install a different version of Compose, substitute 1.28.6 with the version of Compose you want to use.

  2. Apply executable permissions to the binary:

    sudo chmod +x /usr/local/bin/docker-compose
  3. Test the installation:

    docker-compose --version

 Join Our Monthly Newsletter

Get the latest news and popular articles to your inbox every month

We never send SPAM nor unsolicited emails

0 Comments

Leave a Reply

Your email address will not be published.

Replying to the message: View original

Hey visitor! Unlock access to featured articles, remove ads and much more - it's free.