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 test.docker.com -o get-docker.sh $ curl -fsSL get.docker.com -o get-docker.sh $ sudo sh get-docker.sh --mirror Aliyun # $ sudo sh get-docker.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 \ lsb-release
To confirm the validity of the downloaded software package, the GPG key of the software source needs to be added.
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg # Official source # curl -fsSL https://download.docker.com/linux/ubuntu/gpg | 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] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \ $(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] https://download.docker.com/linux/ubuntu \ # $(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 containerd.io # 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": ["https://docker.mirrors.ustc.edu.cn/"] } # 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: [Service] Environment="HTTP_PROXY=http://ip:port/" Environment="HTTPS_PROXY=http://ip:port/" Environment="NO_PROXY=localhost,127.0.0.1,.example.com" # 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 https://github.com/docker/compose/releases
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 wget https://github.com/docker/compose/releases/download/v2.10.0/docker-compose-linux-aarch64 # 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) - - - - ...
image
Portainer
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 \ portainer/portainer # docker compose start # docker-compose.yml version: '3.7' services: portainer: container_name: portainer image: "portainer/portainer" volumes: - ./docker:/data - /var/run/docker.sock:/var/run/docker.sock:ro - /etc/localtime:/etc/localtime:ro ports: - "9000:9000" restart: always # End of file docker compose up -d
HomeAssistant
Intelligent Home Furnishing system
# Fast pass, but low version docker pull docker.mirrors.ustc.edu.cn/homeassistant/home-assistant # Slow and various failures, but the self test can be accelerated by using the image source of ustc docker pull ghcr.io/home-assistant/home-assistant:stable # Direct start docker run -d \ --name homeassistant \ --privileged \ --restart=unless-stopped \ -e TZ=Asia/Shanghai \ -v ./homeassistant:/config \ --network=host \ ghcr.io/home-assistant/home-assistant:stable # docker compose start # docker-compose.yml version: '3.7' services: homeassistant: container_name: homeassistant image: "ghcr.io/home-assistant/home-assistant" volumes: - ./homeassistant:/config - /etc/localtime:/etc/localtime:ro restart: unless-stopped privileged: true network_mode: host environment: - TZ=Asia/Shanghai # End of file docker compose up -d