原文:https://blog.csdn.net/hello_junz/article/details/79882602
centos离线安装docker-ce
目前越来越多的应用采用docker部署管理,使快速的部署集成变得更容易。但笔者在安装docker时,遇到一个问题,目标服务器无法联网,这就要求我们能够采用离线的方式安装docker。下面就如何离线安装docker,列出了实施步骤,与大家一起分享。
1. 系统环境
Centos7 Linux version 3.10.0-327.10.1.el7.x86_64
2. docker-ce版本
18.03.0.ce-1.el7.centos.x86_64
3. 在可以联网的机器上制作docker本地安装源
3.1 安装一个虚拟机,然后在虚拟机里面安装centos7(当然,也可以一台可以联网安装了centos7系统的主机)
3.2 创建离线包存放目录,并赋予读写权限
- # mkdir -p /home/docker/local
- # chmod -R 777 /home/docker/local
3.3 创建docker的yum repository
3.3 下载离线docker-ce依赖包
注意,下面指令仅仅下载离线包到指定目录。后面要用到。
- yum install --downloadonly --downloaddir=/home/docker/local yum-utils \
- device-mapper-persistent-data \
- lvm2 createrepo
3.4安装docker-ce依赖包及createrepo
- yum install yum-utils \
- device-mapper-persistent-data \
- lvm2 createrepo
3.5 配置docker repository
- yum-config-manager \
- --add-repo \
- https://download.docker.com/linux/centos/docker-ce.repo
3.6 更新yum源索引
yum makecache fast
3.7下载离线docker-ce安装包
yum install --downloadonly --downloaddir=/home/docker/local docker-ce
3.8 获取安装docker需要的密匙
查看密匙文件url
- [jerry@localhost ~]$ more /etc/yum.repos.d/docker-ce.repo
- [docker-ce-stable]
- name=Docker CE Stable - $basearch
- baseurl=https://download.docker.com/linux/centos/7/$basearch/stable
- enabled=1
- gpgcheck=1
- gpgkey=https://download.docker.com/linux/centos/gpg
- [docker-ce-stable-debuginfo]
- name=Docker CE Stable - Debuginfo $basearch
- baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/stable
- enabled=0
- gpgcheck=1
- gpgkey=https://download.docker.com/linux/centos/gpg
下载密匙文件(存放到/home/docker/local下)
- cd /home/docker/local
- wget https://download.docker.com/linux/centos/gpg
3.9 初始化安装源repodata库
- # createrepo -pdo /home/docker/local /home/docker/local
- # createrepo --update /home/docker/local
此时,/home/docker/local下面应该有如下安装包、文件及目录
- container-selinux-2.42-1.gitad8f0f7.el7.noarch.rpm
- createrepo-0.9.9-28.el7.noarch.rpm
- device-mapper-1.02.140-8.el7.x86_64.rpm
- device-mapper-event-1.02.140-8.el7.x86_64.rpm
- device-mapper-event-libs-1.02.140-8.el7.x86_64.rpm
- device-mapper-libs-1.02.140-8.el7.x86_64.rpm
- device-mapper-persistent-data-0.7.0-0.1.rc6.el7_4.1.x8
- docker-ce-18.03.0.ce-1.el7.centos.x86_64.rpm
- dracut-033-502.el7_4.1.x86_64.rpm
- dracut-config-rescue-033-502.el7_4.1.x86_64.rpm
- dracut-network-033-502.el7_4.1.x86_64.rpm
- libgudev1-219-42.el7_4.10.x86_64.rpm
- libseccomp-2.3.1-3.el7.x86_64.rpm
- libselinux-2.5-11.el7.x86_64.rpm
- libselinux-python-2.5-11.el7.x86_64.rpm
- libselinux-utils-2.5-11.el7.x86_64.rpm
- libsemanage-2.5-8.el7.x86_64.rpm
- libsemanage-python-2.5-8.el7.x86_64.rpm
- libsepol-2.5-6.el7.x86_64.rpm
- lvm2-2.02.171-8.el7.x86_64.rpm
- lvm2-libs-2.02.171-8.el7.x86_64.rpm
- pigz-2.3.3-1.el7.centos.x86_64.rpm
- policycoreutils-2.5-17.1.el7.x86_64.rpm
- policycoreutils-python-2.5-17.1.el7.x86_64.rpm
- python-urlgrabber-3.10-8.el7.noarch.rpm
- rpm-4.11.3-25.el7.x86_64.rpm
- rpm-build-libs-4.11.3-25.el7.x86_64.rpm
- rpm-libs-4.11.3-25.el7.x86_64.rpm
- rpm-python-4.11.3-25.el7.x86_64.rpm
- selinux-policy-3.13.1-166.el7_4.9.noarch.rpm
- selinux-policy-targeted-3.13.1-166.el7_4.9.noarch.rpm
- setools-libs-3.3.8-1.1.el7.x86_64.rpm
- systemd-219-42.el7_4.10.x86_64.rpm
- systemd-libs-219-42.el7_4.10.x86_64.rpm
- systemd-python-219-42.el7_4.10.x86_64.rpm
- systemd-sysv-219-42.el7_4.10.x86_64.rpm
- yum-3.4.3-154.el7.centos.1.noarch.rpm
- yum-utils-1.1.31-42.el7.noarch.rpm
- repodata
- gpg
3.10 打包导出安装源
# cd /home/docker/local# tar -zcvf docker-local.tar.gz *
docker-local.tar.gz这个文件,就是我们制作好的离线安装源。
4.将docker-local.tar.gz copy到无法联网的centos7 服务器上(比如/home/docker/local目录下),并解压
- # mkdir -p /home/docker/local (如果不存在此目录,则创建,然后copy docker-local.tar.gz到此目录)
- # cd /home/docker/local
- # tar -zxvf docker-local.tar.gz
5 安装createrepo
- # cd /home/docker/local
- # rpm -ivh createrepo-0.9.9-28.el7.noarch.rpm (这个rpm安装包就是上面我们离线下载的安装包)
6 备份安装源
- # cd /etc/yum.repos.d/
- # mkdir repobak
- # mv * repobak/
7 配置离线安装源
- # vi /etc/yum.repos.d/docker-ce-local.repo
- [docker]
- name=docker local
- baseurl=file:///home/docker/local/
- gpgcheck=0
- enabled=1
- gpgkey=file:///home/docker/local/gpg
8 构建本地安装源
# createrepo -d /home/docker/local/repodata# yum clean all (清除缓存)
# yum makecache (创建缓存)
9 检查本地库是否制作成功
# yum repolist
repo id repo
name status
docker docker
local 38
repolist: 38
10. 安装docker-ce
# yum install docker-ce
11.检查是否安装成功
- # systemctl start docker
- # docker version
- Client:
- Version: 18.03.0-ce
- API version: 1.37
- Go version: go1.9.4
- Git commit: 0520e24
- Built: Wed Mar 21 23:09:15 2018
- OS/Arch: linux/amd64
- Experimental: false
- Orchestrator: swarm
- Server:
- Engine:
- Version: 18.03.0-ce
- API version: 1.37 (minimum version 1.12)
- Go version: go1.9.4
- Git commit: 0520e24
- Built: Wed Mar 21 23:13:03 2018
- OS/Arch: linux/amd64
- Experimental: false
12. 创建docker用户组
12.1 创建docker用户组
# groupadd docker
12.2 将指定用户(比如ittest)加入docker用户组
# usermod -aG docker ittest
12.3 重启docker
# systemctl restart docker