redhat7.7安装docker

it2024-10-25  37

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.4. 设置stable镜像仓库
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
2.5.更新yum软件包索引
yum makecache fast
2.6.安装DOCKER CE
yum -y install docker-ce
2.7.启动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
最新回复(0)