Docker tossing notes

The systems used are Ubuntu 20.04 (64 bit) and Ubuntu 22.04 (64 bit)

Docker installation

Docker program installation

There are two ways to install Docker: one is to use the official script to install directly, and the other is to use apt to install according to the official tutorial
I have tested both methods. Script installation is very convenient. Manual installation seems troublesome, but the actual operation is not cumbersome
According to the official statement, it is recommended to choose manual installation for customization. However, in my personal attempt, there is no difference between manual installation according to the official tutorial and direct script installation. It is recommended that you directly use script installation

Script installation

In order to simplify the installation process in the test or development environment, Docker official provides a set of convenient installation scripts, which can be installed on Ubuntu system. In addition, you can use the -- mirror option to install from domestic sources:
If you want to install a beta version of Docker, please go to test.Docker Com get script

# $ curl -fsSL -o
$ curl -fsSL -o
$ sudo sh --mirror Aliyun
# $ sudo sh --mirror AzureChinaCloud

After executing this command, the script will automatically complete all preparations and install the stable version of Docker in the system.

Manual installation

Since the apt source uses HTTPS to ensure that the software is not tampered with during the download process. Therefore, we first need to add the software package and CA certificate transmitted using HTTPS.

sudo apt-get update

sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \

To confirm the validity of the downloaded software package, the GPG key of the software source needs to be added.

curl -fsSL | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

# Official source
# curl -fsSL | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Then, we need to apply to sources Add Docker software source to the list

echo \
  "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Official source
# echo \
#   "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] \
#   $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Update apt package cache and install docker CE

sudo apt-get update

sudo apt-get install docker-ce docker-ce-cli # After the test, the two have been included in the first

docker compose installation

Install the compose instruction of docker. After that, you can execute the compose instruction through docker compose xxx (the script installation will also automatically install the docker compose instruction)

sudo apt-get install docker-compose-plugin

Docker startup

sudo systemctl enable docker
sudo systemctl start docker

Create docker user group

sudo groupadd docker # Create docker user group
sudo usermod -aG docker $USER # Add the current user to the docker group

Log in again after pushing out the terminal

Test whether Docker is installed correctly

docker run --rm hello-world

If no error is reported, the installation is successful

Docker acceleration

Docker set up the accelerated image source

sudo nano /etc/docker/daemon.json
# daemon.json
  "registry-mirrors": [""]
# End of file

systemctl restart docker

docker pull agent

docker pull is executed by the daemon dockerd Therefore, the agent needs to be configured in the docked environment, which is controlled by systemd, so it is actually the configuration of systemd

I.e. HTTP of export_ Proxy is also invalid

sudo mkdir -p /etc/systemd/system/docker.service.d
sudo nano /etc/systemd/system/docker.service.d/proxy.conf
# Input:
# Reload systemd after saving
sudo systemctl daemon-reload
sudo systemctl restart docker

Docker Compose

Docker compose installation

The new version of Docker already comes with compose. Enter

docker compose version
> Docker Compose version v2.6.0

This means that docker compose is already in the system
However, it should be noted that the default self-contained compose is a docker command, so the two are connected by spaces

If docker compose is not found, you need to download it yourself

go to
After finding the latest version, click in, select the version corresponding to your own system, and copy the link

The system version can be viewed through uname -a

# Using wget to download, curl does not know why the download may be incomplete
# My system is aarch64 of linux
# After downloading, transfer the file to / usr/local/bin
sudo mv docker-compose-linux-aarch64 /usr/local/bin/docker-compose
# Add executable permissions
sudo chmod +x /usr/local/bin/docker-compose
# Establish a soft link to / usr/bin
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
# Check if the installation is successful
docker-compose --version
> Docker Compose version v2.10.0

Docker Compose use

First, about why all docker compose configuration files are named docker-compose.yml
Because docker compose is bound to the current directory during execution, docker-compose.yml without directory does not conflict with each other
Therefore, the recommended docker project directory structure is:

- Dockers
- - homeassistant(Application composed of single container)
- - - docker-compose.yml
- - - homeassistant
- - - - (homeassistant Container config Directory mapping)
- - - - configuration.yaml
- - - - custom_components
- - - - ...

- - yunzai-bot(Application of two containers)
- - - docker-compose.yml
- - - yunzai
- - - - (yunzai Directory mapping for containers)
- - - - config
- - - - data
- - - - plugins
- - - - ...
- - - redis
- - - - (redis Directory mapping for containers)
- - - - ...



Docker's webUI interface, very recommended

docker pull portainer/portainer

docker run -d \
  --name portainer \
  -v ./portainer:/data \
  -v /var/run/docker.sock:/var/run/docker.sock:ro \
  -v /etc/localtime:/etc/localtime:ro \
  -p 9000:9000 \
  --restart=always \

# docker compose start
# docker-compose.yml
version: '3.7'
    container_name: portainer
    image: "portainer/portainer"
      - ./docker:/data
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /etc/localtime:/etc/localtime:ro
      - "9000:9000"
    restart: always
# End of file
docker compose up -d


Intelligent Home Furnishing system

# Fast pass, but low version
docker pull
# Slow and various failures, but the self test can be accelerated by using the image source of ustc
docker pull

# Direct start
docker run -d \
  --name homeassistant \
  --privileged \
  --restart=unless-stopped \
  -e TZ=Asia/Shanghai \
  -v ./homeassistant:/config \
  --network=host \

# docker compose start
# docker-compose.yml
version: '3.7'
    container_name: homeassistant
    image: ""
      - ./homeassistant:/config
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    privileged: true
    network_mode: host
      - TZ=Asia/Shanghai
# End of file
docker compose up -d

Tags: Linux Docker Ubuntu

Posted by Paavero on Sat, 27 Aug 2022 13:50:30 +0300