Linux 安装 Docker
Docker 分为 CE 和 EE 两大版本。CE 即社区版(免费,支持周期 7 个月),EE 即企业版,强调安全,付费使用,支持周期 24 个月。Docker CE 分为 stable
test
和 nightly
三个更新频道。官方网站上有各种环境下的 安装指南,这里主要介绍 Docker CE 在 CentOS上的安装。Docker CE 支持 64 位版本 CentOS 7,并且要求内核版本不低于 3.10, CentOS 7 满足最低内核的要求,所以我们在 CentOS 7 安装 Docker
在线安装
Step 1:卸载(可选)
如果之前安装过旧版本的Docker,可以使用下面命令卸载:
yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-selinux \ docker-engine-selinux \ docker-engine \ docker-ce \ podman \ runc
Step 2:安装
首先需要联网,安装 yum 工具
yum install -y yum-utils \ device-mapper-persistent-data \ lvm2 --skip-broken
然后更新本地镜像源:
# 设置docker镜像源 yum-config-manager \ --add-repo \ https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo sed -i 's/download.docker.com/mirrors.aliyun.com\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo yum makecache fast
然后输入命令:
yum install -y docker-ce
docker-ce 为社区免费版本。稍等片刻,docker 即可安装成功
Step 3:启动
通过命令启动 Docker :
# 启动 docker 服务 systemctl start docker # 停止 docker 服务 systemctl stop docker # 重启 docker 服务 systemctl restart docker
然后输入命令,可以查看 docker 版本:
docker -v
Step 4:配置镜像加速
Docker 官方镜像仓库网速较差,我们需要设置国内镜像服务:参考阿里云的镜像加速文档:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
源码安装
Step 1:下载源码
安装包官方地址:https://download.docker.com/linux/static/stable/x86_64/
可以先下载到本地,然后通过 ftp工具上传到服务器上,或者在服务器上使用命令下载
wget https://download.docker.com/linux/static/stable/x86_64/docker-18.06.3-ce.tgz
Step 2:解压与安装
tar -zxvf docker-18.06.3-ce.tgz
3.3 将解压出来的docker文件复制到 /usr/bin/ 目录下
cp docker/* /usr/bin/
Step 3:配置 service 服务
在/etc/systemd/system/目录下新增docker.service文件**,内容如下,这样可以将docker注册为service服务
[Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network-online.target firewalld.service Wants=network-online.target [Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/bin/dockerd --selinux-enabled=false --insecure-registry=127.0.0.1 ExecReload=/bin/kill -s HUP $MAINPID # Having non-zero Limit*s causes performance problems due to accounting overhead # in the kernel. We recommend using cgroups to do container-local accounting. LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity # Uncomment TasksMax if your systemd version supports it. # Only systemd 226 and above support this version. #TasksMax=infinity TimeoutStartSec=0 # set delegate yes so that systemd does not reset the cgroups of docker containers Delegate=yes # kill only the docker process, not all processes in the cgroup KillMode=process # restart the docker process if it exits prematurely Restart=on-failure StartLimitBurst=3 StartLimitInterval=60s [Inst:all] WantedBy=multi-user.target
此处的 --insecure-registry=127.0.0.1(此处改成你私服 ip)设置是针对有搭建了自己私服 Harbor 时允许 docker 进行不安全的访问,否则访问将会被拒绝。
Step 4:启动
给docker.service文件添加执行权限
chmod +x /etc/systemd/system/docker.service
重新加载配置文件(每次有修改docker.service文件时都要重新加载下)
systemctl daemon-reload
启动
systemctl start docker
设置开机启动
systemctl enable docker.service
查看docker服务状态
systemctl status docker
上图表示docker已安装成功
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现