This repository contains a robust bash script (docker_engine_install.sh) designed to automate the installation of the official Docker Engine on Debian-based Linux distributions like Ubuntu, Debian, Linux Mint, etc.
It simplifies the process by handling:
- Uninstalling older or conflicting Docker packages (
docker.io,podman-docker, etc.). - Setting up Docker's official APT repository correctly.
- Installing the latest stable versions of Docker Engine, CLI, containerd, Docker Buildx plugin, and Docker Compose plugin.
- Performing essential post-installation steps like adding the current user to the
dockergroup. - Offering options to configure Docker's
daemon.jsonwith sensible defaults or a custom data directory.
- Idempotent Uninstallation: Checks for and removes known older/conflicting packages.
- Official Repository Setup: Correctly adds Docker's GPG key and APT repository source.
- Modular Repository Setup: Utilizes a dedicated helper script (
docker_engine_repo.sh) for clear and focused APT repository management. - Prerequisite Handling: Installs necessary dependencies like
ca-certificates,curl,gnupg,lsb-release, andjq. - Latest Stable Docker: Installs
docker-ce,docker-ce-cli,containerd.io,docker-buildx-plugin,docker-compose-plugin. - User Group Management: Automatically adds the user running the script (via
sudo) to thedockergroup for passwordless Docker command execution (requires logout/login). - Optional Default Configuration (
-c): Creates/updates/etc/docker/daemon.jsonto set log rotation limits (json-filedriver, 10m size, 3 files) and enable BuildKit. Merges settings safely if the file exists and is valid JSON. - Optional Custom Data Root (
-d <path>): Configures Docker to use a specified directory for storing images, containers, volumes, etc., by setting thedata-rootoption in/etc/docker/daemon.json. Merges settings safely. - Robust JSON Handling: Uses
jqto safely create or modify the/etc/docker/daemon.jsonfile. - Safety Checks: Includes
set -e,set -o pipefail, and requires root/sudo privileges to run.
- A Debian-based Linux distribution (e.g., Ubuntu 20.04+, Debian 10+, Linux Mint 20+, etc.).
sudoprivileges.- An active internet connection to download packages and GPG keys.
docker_engine_install.sh: The main installation and configuration script.docker_engine_repo.sh: Helper script called bydocker_engine_install.shto set up Docker's APT repository.
-
Download or Clone the Script:
git clone https://github.com/phreck/Docker_Engine_Ubuntu.git cd Docker_Engine_UbuntuOr download the
docker_engine_install.shfile directly. -
Make the Script Executable:
chmod +x docker_engine_install.sh
-
Run the Script with
sudo:-
Standard Installation:
sudo ./docker_engine_install.sh
-
Install and Configure Default
daemon.json:sudo ./docker_engine_install.sh -c
-
Install and Configure Custom Data Root:
# Make sure the parent directory (e.g., /mnt) exists and is suitable sudo ./docker_engine_install.sh -d /mnt/my-docker-data(The script configures Docker to use this path; the Docker daemon will attempt to create the final directory if it doesn't exist when it starts)
-
Install with Both Default Config and Custom Data Root:
sudo ./docker_engine_install.sh -c -d /var/lib/docker-custom-directory
-
Display Help Message:
./docker_engine_install.sh -h
-
-c: Create or update/etc/docker/daemon.json. If the file exists and is valid JSON, merges the default settings below. If the file doesn't exist or is invalid, it will be created/overwritten with these settings (plus any-dsetting).-d <path>: Set a custom absolute path for Docker's data-root directory in/etc/docker/daemon.json. Merges the setting if the file exists and is valid JSON. Requires an absolute path (e.g.,/opt/docker).-h: Display the help message and exit.
When the -c flag is used, the script aims to configure /etc/docker/daemon.json to include the following settings (merged with existing settings or the -d option):
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
},
"features": {
"buildkit": true
}
}