Docker Installation Manual

Docker\Docker-compose Installation

Here are the steps to install the latest version of Docker Engine and Docker Compose on your Ubuntu system. Docker Compose is now integrated into the Docker CLI and runs as a plugin (i.e. docker compose instead of the old docker-compose).

Preparation

  • Operating system: Ubuntu 20.04 or later.
  • Permissions: root or sudo permissions are required.
  • Network: Make sure the server can access the Docker official repository.

Update the system package index

1sudo apt update
2sudo apt upgrade -y

Install necessary dependencies

Install some necessary tools to add Docker’s official repository:

1sudo apt install -y ca-certificates curl gnupg lsb-release

Add Docker’s GPG key

1sudo mkdir -p /etc/apt/keyrings
2curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

Add Docker official repository

Add Docker’s APT repository to the system:

1echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.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

Update the package index and install the latest version of Docker Engine, CLI, and related components:

1sudo apt update
2sudo apt install -y docker-ce docker-ce-cli containerd.io

Verify Docker installation

Check the Docker version and run a test container:

1docker --version
2sudo docker run hello-world
  • If you see Hello from Docker! output, the installation was successful.

(Optional) Allow non-root users to run Docker

Add the current user to the docker group:

1sudo usermod -aG docker $USER
2newgrp docker
  • Exit and re-login to the terminal to apply the changes.

Install the latest version of Docker Compose

Docker Compose V2 (latest version) is now available as a plugin for the Docker CLI and is no longer a standalone docker-compose tool. Here is how to install it:

Install the Docker Compose plugin

Install the latest version of the Docker Compose plugin via APT:

1sudo apt install -y docker-compose-plugin

Verify Docker Compose installation

Check the version:

1docker compose version
  • Output example: Docker Compose version v2.24.7.
  • Note: The command is docker compose (space separated), not the old-fashioned docker-compose.

(Optional) Manually install the latest version

If the version provided by APT is not the latest, you can manually download it from GitHub Releases:

  1. Check the latest version number: Visit https://github.com/docker/compose/releases.
  2. Download and install (replace with the latest version, below takes v2.24.7 as an example):
1DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
2mkdir -p $DOCKER_CONFIG/cli-plugins
3curl -SL https://github.com/docker/compose/releases/download/v2.24.7/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
4chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose
  1. Verify again:
1docker compose version

Test Docker Compose

Create a simple docker-compose.yml file test environment:

1mkdir ~/test-compose
2cd ~/test-compose
3nano docker-compose.yml

Paste the following:

1version: '3'
2services:
3web:
4image: nginx:latest
5ports:
6- "8080:80"

Save and exit (Ctrl+O, Enter, Ctrl+X). Start the service:

1docker compose up -d
  • Visit http://your server IP:8080, you should see the Nginx welcome page. Stop and clean up:
1docker compose down

Optimization

Domestic network optimization (skip if docker pulls the image normally):

  • Installation on domestic servers may not be able to access docker, and image acceleration or proxy needs to be configured. The proxy method requires a foreign server and is accessible domestically, which is not recommended. Configure image acceleration and edit /etc/docker/daemon.json:
 1{
 2  "registry-mirrors": [
 3     "https://docker.unsee.tech",
 4     "https://dockerpull.org",
 5     "https://dockerhub.icu",
 6     "https://docker.registry.cyou",
 7     "https://docker-cf.registry.cyou",
 8     "https://dockercf.jsdelivr.fyi",
 9     "https://docker.jsdelivr.fyi",
10     "https://dockertest.jsdelivr.fyi",
11     "https://mirror.aliyuncs.com",
12     "https://dockerproxy.com",
13     "https://mirror.baidubce.com",
14     "https://docker.m.daocloud.io",
15     "https://docker.nju.edu.cn",
16     "https://docker.mirrors.sjtug.sjtu.edu.cn",
17     "https://docker.mirrors.ustc.edu.cn",
18     "https://mirror.iscas.ac.cn",
19     "https://docker.rainbond.cc",
20     "https://do.nark.eu.org",
21     "https://dc.j8.work",
22     "https://dockerproxy.com",
23     "https://gst6rzl9.mirror.aliyuncs.com",
24     "https://registry.docker-cn.com",
25     "http://hub-mirror.c.163.com",
26     "http://mirrors.ustc.edu.cn/",
27     "https://mirrors.tuna.tsinghua.edu.cn/"
28  ]
29}
  • Restart Docker:
1sudo systemctl daemon-reload
2sudo systemctl restart docker
Licensed under CC BY-NC-SA 4.0
Built with Hugo
Theme Stack designed by Jimmy
Published 7 posts · Total 7.54k words
This site has been running stably for 0 days 00 hours 00 minutes 00 seconds