跳到主要内容

安装配置

安装 Docker

在 Debian11 上安装

for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do apt remove $pkg; done
apt update \
&& apt install ca-certificates curl gnupg \
&& install -m 0755 -d /etc/apt/keyrings \
&& curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg \
&& chmod a+r /etc/apt/keyrings/docker.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
apt update \
&& apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

在 CentOS7 上安装

yum -y remove docker docker-common docker-selinux docker-engine
yum -y install yum-utils device-mapper-persistent-data lvm2 \
&& yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo \
yum -y install docker-ce

设置 docker 国内镜像源

{
"registry-mirrors":["http://hub-mirror.c.163.com"]
}
mkdir -p /etc/docker \
&& echo '{ "registry-mirrors":["http://hub-mirror.c.163.com"] }' > /etc/docker/daemon.json

:::success 第三方国内镜像源

第三方 Docker Hub:https://docker.fxxk.dedyn.io/

https://dockerproxy.com/docs

来源地址
Docker中国区官方镜像https://registry.docker-cn.com
网易http://hub-mirror.c.163.com
中国科技大学https://docker.mirrors.ustc.edu.cn
上海交通大学https://docker.mirrors.sjtug.sjtu.edu.cn
Hub Proxyhttps://hub.rat.dev/

:::

安装 docker-compose

现在一般不用手动安装了,跟着官方文档安装好docker engine之后,docker-compose就会自动安装好了。

apt update
apt install -y docker-compose-plugin
yum update
yum install -y docker-compose-plugin
curl -L "https://github.com/docker/compose/releases/download/2.11.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker compose version

配置HTTP代理

mkdir -p /etc/systemd/system/docker.service.d \
nano /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://<你的代理>:<端口>"
Environment="HTTPS_PROXY=http://<你的代理>:<端口>"
Environment="NO_PROXY=localhost,127.0.0.1,docker-registry.example.com"
systemctl daemon-reload
systemctl restart docker
systemctl show --property=Environment docker