Centos系统安装Docker
在线安装1. 更新yum源2. 更新yum-utils源3. 安装docker4. 安装docker-compose4.1 添加docker的yum镜像源4.2 安装docker插件5. 查看docker版本 离线安装1.下载docker离线包2.解压离线包3.将解压的docker拷贝或移动到/usr/bin/目录下4.编写docker.service 文件加入Linux服务当中并开启守护进程5.添加文件可执行权限6.配置成功后,重新加载 daemon 服务7.启动 docker 服务 常见问题镜像拉取失败设置镜像源地址
在线安装
1. 更新yum源
yum update
2. 更新yum-utils源
yum install -y yum-utils
3. 安装docker
yum install -y docker
4. 安装docker-compose
使用到docker-compose.yml部署项目时需要安装此功能
4.1 添加docker的yum镜像源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
4.2 安装docker插件
yum -y install docker-compose-plugin
5. 查看docker版本
[root@localhost ~]# docker -vDocker version 24.0.5, build ced0996[root@localhost ~]# docker compose versionDocker Compose version v2.20.3
在线安装步骤已经结束,下面是离线安装的步骤。
离线安装
本教程采用二进制安装
1.下载docker离线包
如果您还未下载离线包,链接下载? http://blog.fusuccess.top/software/docker-24.0.5.tgz.tar
若想下载其他版本请至官网下载 https://download.docker.com/linux/static/stable/x86_64/
2.解压离线包
tar xvf docker-24.0.5.tgz.tar
3.将解压的docker拷贝或移动到/usr/bin/目录下
cp docker/* /usr/bin/
4.编写docker.service 文件加入Linux服务当中并开启守护进程
vim /etc/systemd/system/docker.service
添加内容:
[Unit]Description=Docker Application Container EngineDocumentation=https://docs.docker.comAfter=network-online.target firewalld.serviceWants=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 dockerExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock --selinux-enabled=false --default-ulimit nofile=65536:65536ExecReload=/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=infinityLimitNPROC=infinityLimitCORE=infinity# Uncomment TasksMax if your systemd version supports it.# Only systemd 226 and above support this version.#TasksMax=infinityTimeoutStartSec=0# set delegate yes so that systemd does not reset the cgroups of docker containersDelegate=yes# kill only the docker process, not all processes in the cgroupKillMode=process# restart the docker process if it exits prematurelyRestart=on-failureStartLimitBurst=3StartLimitInterval=60s [Install]WantedBy=multi-user.target
5.添加文件可执行权限
chmod +x /etc/systemd/system/docker.service
6.配置成功后,重新加载 daemon 服务
systemctl daemon-reload
7.启动 docker 服务
systemctl start docker
常见问题
镜像拉取失败
设置镜像源地址
mkdir -p /etc/docker;vi /etc/docker/daemon.json
文件内容
{ "registry-mirrors": [ "https://ustc-edu-cn.mirror.aliyuncs.com/", "https://ccr.ccs.tencentyun.com/", "https://docker.m.daocloud.io/" ]}
重启docker
sudo systemctl daemon-reload#重启daemon进程sudo systemctl restart docker#重启docker