How To Install docker and docker-compose in Ubuntu Server

Posted by Ray on July 15, 2023

This document is a guide for installing docker and docker compose to an Ubuntu server.

Installing Docker

  1. Update and upgrade system repository and system packages
    1
    2
    
    $ sudo apt update
    $ sudo apt upgrade
    

    sudo_apt_update sudo_apt_upgrade

  2. Install docker dependencies
    1
    
    $ sudo apt install lsb-release ca-certificates apt-transport-https software-properties-common -y
    

    install_docker_dependencies

  3. Add Docker repository to system resources
    1
    2
    3
    
    $ sudo snap install curl
    $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
    $ echo "deb [arch=$(dpkg --print-architecture) 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
    

    add_docker_repository

  4. Update and upgrade system packages
    1
    2
    
    $ sudo apt update
    $ sudo apt upgrade
    

    update_and_upgrade

  5. Install Docker
    1
    
    $ sudo apt install docker-ce
    

    install_docker

  6. Check docker status and version
    1
    2
    
    $ sudo systemctl status docker
    $ docker --version
    

    check_docker_status

Installing Docker Compose

  1. Install Docker Compose using apt
    1
    
    $ sudo apt install docker-compose
    

    install_docker_compose

  2. Check docker-compose version
    1
    
    $ docker-compose --version
    

    docker_compose_version

Done!