Loading... ## 在 Linux环境下安装Docker ### Debian/Ubuntu 首先要安装依赖 ```bash apt-get update apt-get install ca-certificates curl gnupg -y ``` 信任 Docker 的 GPG 公钥并添加仓库: debian: ```bash install -m 0755 -d /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg sudo 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 ``` ubuntu ```bash install -m 0755 -d /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg sudo 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/ubuntu \ "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \ tee /etc/apt/sources.list.d/docker.list > /dev/null ``` 最后安装docker ```bash apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin ``` 安装完成之后设置为开机自启 ```bash systemctl enable --now docker ``` ### RHEL系列操作系统 安装相关依赖,下载repo文件 ```bash yum install -y yum-utils yum-config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo sed -i 's+https://download.docker.com+https://mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo ``` 安装docker ```bash yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin ``` 同样,安装完成最后不要忘了设置开机自启 ```bash systemctl enable --now docker ``` ### 配置镜像加速 因为某些不可描述的原因无法使用Docker官方镜像仓库,这里提供几种加速的方法 1、通过更改镜像源实现加速 修改 `/etc/docker/daemon.json` 文件(如果不存在则创建),内容如下 ```json { "registry-mirrors": ["https://docker.1ms.run"] } ``` 然后重启Docker ```bash systemctl daemon-reload && systemctl restart docker ``` 2、自建缓存服务器 参考公众号文章:https://mp.weixin.qq.com/s/6zjn49zH-z7eBlt6Os1TeQ 3、使用开源项目,CRProxy自建代理服务器,简单来说与上一个的区别就是不会缓存镜像到你的服务器,仅限代理 参考:https://zhuanlan.zhihu.com/p/711282751 Last modification:April 25, 2025 © Allow specification reprint Support Appreciate the author Like 如果觉得我的文章对你有用,请随意赞赏