docker

关注公众号 jb51net

关闭
首页 > 网站技巧 > 服务器 > 云和虚拟化 > docker > redhat7.7安装docker

redhat7.7安装docker全过程

作者:柿饼zzzz

文章详细介绍了如何从二进制文件安装Docker,并涵盖了安装过程中的关键步骤,包括准备工作、卸载旧版本、设置镜像仓库、启动Docker、设置开机自启动以及配置镜像加速等

1、准备

官网有二进制文件安装的详细过程可参阅:https://docs.docker.com/engine/install/binaries/

下载二进制安装包:

转到 https://download.docker.com/linux/static/stable/ (或更改stable为nightly或test),选择您的硬件平台,然后下载.tgz与要安装的Docker Engine版本有关的文件。

2、安装

2.1 安装gcc相关环境

yum -y install gcc
yum -y install gcc-c++

2.2. 卸载旧版本,并安装需要的软件包

#卸载
yum -y remove docker docker-common docker-selinux docker-engine
yum install -y yum-utils device-mapper-persistent-data lvm2

2.3. 设置stable镜像仓库

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

2.4.更新yum软件包索引

yum makecache fast

2.5.安装DOCKER CE

yum -y install docker-ce

2.6.启动docker与测试

#启动
systemctl start docker
#测试
docker version
docker run hello-world

3、设置开机自启动

#关闭docker服务
kill -9 *** 
#创建启动文件
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 tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
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 

#赋权
chmod +x /etc/systemd/system/docker.service

4、验证

# 重载systemd下 xxx.service文件
systemctl daemon-reload   
# 启动Docker
systemctl start docker     
#重启
systemctl restart docker
# 设置开机自启 
systemctl enable docker.service   
注这时候systemctl stop docker 命令可能不成功,reboot重启后所有命令生效
完成用二进制文件安装docker!!

5、docker run报错

#报错container init caused \“write /proc/self/attr/keycreate: permission denied\““: unknown
原因“/proc/self/attr/keycreate” 这里没有写入权限,把“/etc/selinux/config”里面的SELINUX值修改为disabled
SELINUX=disabled

6、docker镜像本地的导入与恢复

#查看镜像
docker images
#保存本地
docker save 999c20aee5da > /home/artipub.tar 999c20aee5da为镜像ID
#本地导入docker
docker load < /Volumes/SoftWare/artipub.tar
#改名
docker tag 999c20aee5da artipub:latest

7、配置镜像加速

mkdir -p /etc/docker
vim  /etc/docker/daemon.json
systemctl daemon-reload
systemctl restart docker

8、总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文