Signup/Sign In

How to install Docker and Docker Compose on Linux OS

Posted in Programming   LAST UPDATED: JUNE 7, 2023

    Containers are executable components that combine the source code and OS libraries and dependencies so the code can run in any environment. Docker allows you to manage these containers.

    Containers are like lightweight virtual machines that allow you to create portable application images which run on your host’s operating system kernel.

    Docker compose is used to running multiple containers as a single service. Both these containers run individually but they can interact with each other when required. YAML language is used to write Docker compose files which are also called Yet Another Markup Language.

    Let's say if you have an application that requires a server and a database then docker-compose can be used to run both of these containers as a single service.

    Let's know How to install Docker and Docker Compose on Linux OS

    docker compose install

    How to install Docker in Linux

    We are going to install Docker in Linux so you can use Linus's package manager to install the latest version of Docker. You will learn to add Docker's repository, update the package lists, and then we will install Docker.

    1) Debian/Ubuntu

    First, we need to add the dependencies for the installation -

    sudo apt-get update
    sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release

    Then we will add Docker’s repository GPG key by the following command -

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

    Enter the following command to add the repository to your sources and update your package lists -

    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
    sudo apt-get update

    Alright, we are ready to install Docker -

    sudo apt-get install docker-ce docker-ce-cli containerd.io

    2) For Fedora

    First of all, add Docker’s package repository -

    sudo dnf -y install dnf-plugins-core
    sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo

    Install Docker:

    sudo dnf install docker-ce docker-ce-cli containerd.io

    3) For CentOS

    Add Docker’s package repository:

    sudo yum -y install yum-utils
    sudo yum-config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo

    then Install Docker:

    sudo yum install docker-ce docker-ce-cli containerd.io

    Test if the docker is installed

    Alright, we have successfully installed Docker in our Linux Operating System, Now we will check if it is properly installed or not. You can use the hello-world image.

    docker run hello-world:latest

    docker install

    The Docker will first look for the hello-world:latest image on your machine, if it doesn't exist on your machine then Docker will get it from the Docker Hub repository.

    Now, Let's add Docker Compose

    Go to the Docker Compose's releases page and check out the latest version or the version you want to install on your machine.

    Docker compose is a separate binary so it can be directly downloaded from the project's GitHub releases. At the time of writing, the latest version is 2.7.0.

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

    Replace the 2.7.0 with the version you want to install. This command will download the binary in /use/local/bin.

    Now, you have to make the executable file -

    sudo chmod +x /usr/local/bin/docker-compose

    You can use the docker-compose --version command in your terminal to check if the docker-compose is installed or not.

    Create a Docker-Compose File

    To use docker-compose, you'll need to have a docker-compose.yml file. You can specify many things that are to be used by the docker containers like port bindings, environment variables, etc. This docker-compose.yml file describes the containers.

    Containers that are declared in the same docker-compose.yml file are linked to a Docker network so the containers can communicate with each other using the service names of docker-compose.yml.

    Conclusion

    Installing Docker and Docker Compose on a Linux operating system is a game-changer for developers and system administrators. The versatility and efficiency of Docker containers provide a seamless environment for deploying applications and managing software dependencies. By following the detailed instructions outlined in this article, you can confidently navigate the installation process and unlock the full potential of Docker.

    With Docker, you can streamline your development workflow, simplify application packaging, and ensure consistent deployment across different environments. The ability to isolate applications within containers enables scalability and portability, making it easier to manage complex software systems.

    Docker Compose takes containerization to the next level by allowing you to define and manage multi-container applications. This simplifies the orchestration of interconnected services, facilitating the creation of complex development environments and accelerating collaboration.

    Frequently Asked Questions(FAQs)

    1. What is Docker, and why should I install it on my Linux OS?

    Docker is an excellent tool that lets developers build, ship, and run applications in containers. Installing it on your Linux OS is an excellent idea because it makes it easy to manage and deploy your apps in a lightweight and efficient way.

    2. What are the system requirements for installing Docker and Docker Compose on Linux OS?

    To install Docker and Docker Compose on your Linux OS, you'll need a 64-bit version of the operating system, a compatible Linux kernel version, and enough system resources to run your apps.

    3. How do you install Docker and Docker Compose on Linux OS?

    Installing Docker and Docker Compose on Linux OS is a breeze! You need to add the official Docker repository, install the Docker and Docker Compose packages, and configure Docker to start on boot.

    4. How do I verify that Docker and Docker Compose are installed correctly on my Linux OS?

    To ensure that Docker and Docker Compose are installed and working correctly on your Linux OS, you can type "docker --version" and "docker-compose --version" into the terminal. If you see the correct version numbers, you're good to go!

    About the author:
    Proficient in Java, Python, and web development; has a knack for writing clearly about complex topics. Dedicated to giving readers the tools they need to learn more about computer science and technology.
    Tags:linuxdocker-composehowtodocker
    IF YOU LIKE IT, THEN SHARE IT
     

    RELATED POSTS