dushaoshuai / dushaoshuai.github.io

https://www.shuai.host
0 stars 0 forks source link

Ubuntu 安装 Docker #140

Open dushaoshuai opened 9 months ago

dushaoshuai commented 9 months ago

Install using the apt repository

Set up Docker's apt repository.

# Add tsinghua Docker CE 源 GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

Install the Docker packages.

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Verify that the Docker Engine installation is successful by running the hello-world image.

sudo docker run hello-world

Manage Docker as a non-root user

To create the docker group and add your user:

Create the docker group.

$ sudo groupadd docker

Add your user to the docker group.

$ sudo usermod -aG docker $USER

Activate the changes to groups.

$ newgrp docker

Verify that you can run docker commands without sudo.

$ docker run hello-world

使用国内 Docker Hub 镜像源

现在国内的镜像源都不好使了,我目前是用 clash-verge-rev 的 tun 模式来解决。

/etc/docker/daemon.json:

{
    "registry-mirrors": [
        "https://reg-mirror.qiniu.com",
        "https://ceok5l2c.mirror.aliyuncs.com",
        "https://registry.docker-cn.com",
        "https://hub-mirror.c.163.com/"
    ]
}

(不知道为什么,添加上 https://registry.aliyuncs.com/google_containers/ 会导致 docker 启动/重启失败,有待探究)(因为这是 k8s.gcr.io 的镜像源,不是 Docker Hub 镜像源,😂)

reload Docker for the change to take effect:

sudo systemctl restart docker.service

Install Docker Compose

上面已经安装了 docker-compose-plugin

# Verify that Docker Compose is installed correctly by checking the version.
$ docker compose version
Docker Compose version v2.24.7

参见