Centos7中离线安装DockerCE最新版
转载hsg77 最后发布于2019-05-27 17:16:07 阅读数 764 收藏
Centos7中离线安装DockerCE最新版
来源地址:https://www.cnblogs.com/songxingzhu/p/10651197.html
一、简述
离线在Centos7中部署DockerCE。
二、步骤
(1)在有外网的计算A上执行:
新建一台CentOS7 mini虚拟机,联网下载所有所需的rpm包和其依赖
1、配置安装源存放路径
mkdir -p /root/docker-ce-local && cd /root/docker-ce-local
1
2、获取createrepo安装包
yum install --downloadonly --downloaddir=/root/docker-ce-local createrepo
1
3、获取系统更新yum源
yum update --downloadonly --downloaddir=/root/docker-ce-local
1
4、卸载旧版本
yum remove docker docker-common docker-selinux docker-engine
1
5、获取docker-ce所需依赖
yum install --downloadonly --downloaddir=/root/docker-ce-local yum-utils device-mapper-persistent-data lvm2
yum -y install yum-utils //安装包括yum-config-manager工具
1
2
6、设置docker-ce在线存储库
yum -y install yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
1
2
7、更新yum源索引
yum makecache fast
1
8、获取docker-ce及相关rpm安装源
yum install --downloadonly --downloaddir=/root/docker-ce-local docker-ce
1
9、查看安装时docker所需要的密钥并下载
more /etc/yum.repos.d/docker-ce.repo
cd /root/docker-ce-local/
wget https://download.docker.com/linux/centos/gpg
1
2
3
10、先下载,后安装createrepo
yum install --downloadonly --downloaddir=/root/docker-ce-local createrepo
yum install --downloadonly --downloaddir=/root/docker-ce-local deltarpm libxml2-python python-deltarpm
yum install createrepo
1
2
3
11、初始化源文件的repodata
createrepo -pdo /root/docker-ce-local /root/docker-ce-local
createrepo --update /root/docker-ce-local
1
2
12、将文件夹打包为yum-local.tgz
cd /root
tar -zcvf centos-local.tgz docker-ce-local/
1
2
(2)在目标计算机B上执行:
13、在目标计算机上将tgz包上传至/root路径下,并解压centos-local.tgz文件
cd /root
tar -xvzf centos-local.tgz
1
2
14、安装createrepo
cd /root/docker-ce-local
1
下载libxml2-2.9.1-6.el7_2.3.x86_64.rpm 地址:
https://centos.pkgs.org/7/centos-x86_64/libxml2-2.9.1-6.el7_2.3.x86_64.rpm.html
rpm -qa | grep libxml2 | xargs rpm -e --nodeps
rpm -qa | grep deltarpm| xargs rpm -e --nodeps
rpm -ivh deltarpm-3.6-3.el7.x86_64.rpm
rpm -ivh python-deltarpm-3.6-3.el7.x86_64.rpm
rpm -ivh libxml2-2.9.1-6.el7_2.3.x86_64.rpm
rpm -ivh libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm
rpm -ivh createrepo-0.9.9-28.el7.noarch.rpm
1
2
3
4
5
6
7
# rpm -ivh createrepo-0.9.9-28.el7.noarch.rpm
//注:createrepo版本可能不一样,根据自己下载的包的版本安装
1
2
15、备份安装源 将所有的安装源移动到备份文件夹中
cd /etc/yum.repos.d/
mkdir repobak
mv CentOS* repobak/
1
2
3
16、新增docker-ce-local.repo源文件,写入以下内容
# vi /etc/yum.repos.d/docker-ce-local.repo
[docker-ce-local]
name=Local Yum
baseurl=file:///root/docker-ce-local/
gpgcheck=1
gpgkey=file:///root/docker-ce-local/gpg
enabled=1
1
2
3
4
5
6
7
17、生成源索引及缓存
createrepo /root/docker-ce-local
yum makecache
1
2
18、安装docker-ce
yum install docker-ce
//如果报错,则添加--nogpgcheck跳过公钥检查
yum install docker-ce --nogpgcheck
1
2
3
19、启动并测试
systemctl start docker.service
docker version
1
2
//验证结果
[root@node114 docker-ce-local]# systemctl start docker.service
[root@node114 docker-ce-local]# docker version
Client:
Version: 18.09.6
API version: 1.39
Go version: go1.10.8
Git commit: 481bc77156
Built: Sat May 4 02:34:58 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.6
API version: 1.39 (minimum version 1.12)
Go version: go1.10.8
Git commit: 481bc77
Built: Sat May 4 02:02:43 2019
OS/Arch: linux/amd64
Experimental: false
[root@node114 docker-ce-local]#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
这是下载的离线包文件centos-local.tgz
链接:https://pan.baidu.com/s/1KkD2pSasVEuszI1r2I4TLA
提取码:y4u3
问题集:
1 重启计算机后用docker version报错问题
报错内容如下:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
解决办法:service docker restart
原因可能是上一次没有正常退出docker,所以docker没有正常启动,在相应的/var/run/路径下找不到docker进程。
2关机后或容器关闭后重启容器的方法:
数据还在原处
通过 docker ps -a 看到关闭的容器
docker start your_container_ID
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
52ecb0aa3b1b supermap/iportal "/bin/sh -c /opt/run…" 3 weeks ago Exited (137) 2 days ago iportalserver
9f1c40dd51cf supermap/iserver "/bin/sh -c /opt/run…" 3 weeks ago Exited (137) 2 days ago supermapiserver
712a3f0e5035 8ef3 "container-entrypoin…" 3 weeks ago Exited (0) 2 days ago MYSQL56docker
5c58116a7eb7 nginx "nginx -g 'daemon of…" 3 weeks ago Exited (0) 2 days ago test
1
2
3
4
5
[root@node114 ~]# docker start 712a3f0e5035
712a3f0e5035
[root@node114 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
52ecb0aa3b1b supermap/iportal "/bin/sh -c /opt/run…" 3 weeks ago Exited (137) 2 days ago iportalserver
9f1c40dd51cf supermap/iserver "/bin/sh -c /opt/run…" 3 weeks ago Exited (137) 2 days ago supermapiserver
712a3f0e5035 8ef3 "container-entrypoin…" 3 weeks ago Up 6 seconds 0.0.0.0:3307->3306/tcp MYSQL56docker
5c58116a7eb7 nginx "nginx -g 'daemon of…" 3 weeks ago Exited (0) 2 days ago test
1
2
3
4
5
6
7
8
9
网友评论