Centos系统安装Docker
在线安装
1. 更新yum源
yum update
2. 更新yum-utils源
yum install-y yum-utils
3. 安装docker
yum install-ydocker
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 -yinstall docker-compose-plugin
5. 查看docker版本
[root@localhost ~]# docker -v
Docker version 24.0.5, build ced0996
[root@localhost ~]# docker compose version
Docker 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 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 -H unix:///var/run/docker.sock --selinux-enabled=false --default-ulimit nofile=65536:65536
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
[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
版权归原作者 Fusuccess 所有, 如有侵权,请联系我们删除。