Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Docker Installation Script

This README provides a summary of how the install-docker.sh script installs Docker Community Edition (CE) on Ubuntu. It follows the official Docker documentation and includes additional comments for clarity.

Table of Contents

  1. Overview
  2. Pre-requisites
  3. Steps Explained
  4. Usage
  5. Verification
  6. Further Reading

Overview

This script ensures any outdated or conflicting Docker packages are removed, then sets up the official Docker repository on your system. It installs Docker CE, Docker Compose, and related plugins. Finally, it verifies the installation and optionally configures your system so you can run Docker commands without using sudo.

Pre-requisites

  • An Ubuntu-based system (tested on Ubuntu 22.04, 20.04, etc.).
  • Access to an account with sudo privileges.

Steps Explained

  1. Removing Old Packages

    for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc
    do
      sudo apt-get remove -y "$pkg"
    done
    • Removes any conflicting packages like docker.io or older versions of docker-compose.
  2. Updating Package Index & Installing Dependencies

    sudo apt-get update
    sudo apt-get install -y ca-certificates curl
    • Refreshes package lists.
    • Installs tools needed to manage certificates and make remote requests via HTTPS.
  3. Adding Docker’s Official GPG Key

    sudo install -m 0755 -d /etc/apt/keyrings
    sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
    sudo chmod a+r /etc/apt/keyrings/docker.asc
    • Creates a dedicated directory /etc/apt/keyrings with safe permissions (0755).
    • Downloads and saves Docker’s official GPG key.
    • Adjusts permissions to ensure the key is readable by the package manager.
  4. Adding Docker’s Repository

    echo \
      "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
      $(. /etc/os-release && echo "$VERSION_CODENAME") stable" \
      | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    sudo apt-get update
    • Dynamically inserts system architecture and Ubuntu release codename into the Docker stable repo.
    • Refreshes package lists again, now including Docker’s repo.
  5. Installing Docker Packages

    sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
    • Installs Docker engine, CLI, containerd, Buildx, and the Compose plugin from Docker’s repository.
  6. Verifying Docker Installation

    sudo docker run hello-world
    • Pulls and runs the hello-world Docker image to confirm Docker is functioning properly.
  7. Creating and Configuring the Docker Group

    sudo groupadd docker
    sudo usermod -aG docker $USER
    newgrp docker
    docker run hello-world
    • Creates a user group named docker if it doesn’t exist.
    • Adds your current user to the docker group so you can run Docker commands without sudo.
    • Starts a new shell to load the updated group membership.
    • Confirms the setup by running the hello-world container again without sudo.

Usage

  1. Make the script executable (if not already):

    chmod +x install-docker.sh
  2. Run the script:

    ./install-docker.sh
  3. When the script finishes, Docker should be installed, and you should be able to use Docker as a non-root user (after restarting your session or using newgrp docker).

Verification

  • After installation, you can check your Docker version:
    docker --version
  • Or run a test container:
    docker run hello-world

Further Reading

About

Script created from official installation page code.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages