Docker离线安装教程(Centos7) 转帖

时间:2022-12-20 17:28:46

原文: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 创建离线包存放目录,并赋予读写权限

  1. # mkdir -p /home/docker/local
  2. # chmod -R 777 /home/docker/local

   3.3  创建docker的yum repository

   3.3 下载离线docker-ce依赖包

     注意,下面指令仅仅下载离线包到指定目录。后面要用到。

  1. yum install --downloadonly --downloaddir=/home/docker/local yum-utils \
  2.   device-mapper-persistent-data \
  3.   lvm2 createrepo

  3.4安装docker-ce依赖包及createrepo

  1. yum install yum-utils \
  2.   device-mapper-persistent-data \
  3.   lvm2 createrepo

  3.5 配置docker repository

  1. yum-config-manager \
  2.     --add-repo \
  3.     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

  1. [jerry@localhost ~]$ more /etc/yum.repos.d/docker-ce.repo
  2. [docker-ce-stable]
  3. name=Docker CE Stable - $basearch
  4. baseurl=https://download.docker.com/linux/centos/7/$basearch/stable
  5. enabled=1
  6. gpgcheck=1
  7. gpgkey=https://download.docker.com/linux/centos/gpg
  8.  
  9. [docker-ce-stable-debuginfo]
  10. name=Docker CE Stable - Debuginfo $basearch
  11. baseurl=https://download.docker.com/linux/centos/7/debug-$basearch/stable
  12. enabled=0
  13. gpgcheck=1
  14. gpgkey=https://download.docker.com/linux/centos/gpg

下载密匙文件(存放到/home/docker/local下)

  1. cd /home/docker/local
  2. wget https://download.docker.com/linux/centos/gpg

 3.9 初始化安装源repodata库

  1. # createrepo -pdo /home/docker/local /home/docker/local
  2. # createrepo --update /home/docker/local

 此时,/home/docker/local下面应该有如下安装包、文件及目录

  1. container-selinux-2.42-1.gitad8f0f7.el7.noarch.rpm
  2. createrepo-0.9.9-28.el7.noarch.rpm
  3. device-mapper-1.02.140-8.el7.x86_64.rpm
  4. device-mapper-event-1.02.140-8.el7.x86_64.rpm
  5. device-mapper-event-libs-1.02.140-8.el7.x86_64.rpm
  6. device-mapper-libs-1.02.140-8.el7.x86_64.rpm
  7. device-mapper-persistent-data-0.7.0-0.1.rc6.el7_4.1.x8
  8. docker-ce-18.03.0.ce-1.el7.centos.x86_64.rpm
  9. dracut-033-502.el7_4.1.x86_64.rpm
  10. dracut-config-rescue-033-502.el7_4.1.x86_64.rpm
  11. dracut-network-033-502.el7_4.1.x86_64.rpm
  12. libgudev1-219-42.el7_4.10.x86_64.rpm
  13. libseccomp-2.3.1-3.el7.x86_64.rpm
  14. libselinux-2.5-11.el7.x86_64.rpm
  15. libselinux-python-2.5-11.el7.x86_64.rpm
  16. libselinux-utils-2.5-11.el7.x86_64.rpm
  17. libsemanage-2.5-8.el7.x86_64.rpm
  18. libsemanage-python-2.5-8.el7.x86_64.rpm
  19. libsepol-2.5-6.el7.x86_64.rpm
  20. lvm2-2.02.171-8.el7.x86_64.rpm
  21. lvm2-libs-2.02.171-8.el7.x86_64.rpm
  22. pigz-2.3.3-1.el7.centos.x86_64.rpm
  23. policycoreutils-2.5-17.1.el7.x86_64.rpm
  24. policycoreutils-python-2.5-17.1.el7.x86_64.rpm
  25. python-urlgrabber-3.10-8.el7.noarch.rpm
  26. rpm-4.11.3-25.el7.x86_64.rpm
  27. rpm-build-libs-4.11.3-25.el7.x86_64.rpm
  28. rpm-libs-4.11.3-25.el7.x86_64.rpm
  29. rpm-python-4.11.3-25.el7.x86_64.rpm
  30. selinux-policy-3.13.1-166.el7_4.9.noarch.rpm
  31. selinux-policy-targeted-3.13.1-166.el7_4.9.noarch.rpm
  32. setools-libs-3.3.8-1.1.el7.x86_64.rpm
  33. systemd-219-42.el7_4.10.x86_64.rpm
  34. systemd-libs-219-42.el7_4.10.x86_64.rpm
  35. systemd-python-219-42.el7_4.10.x86_64.rpm
  36. systemd-sysv-219-42.el7_4.10.x86_64.rpm
  37. yum-3.4.3-154.el7.centos.1.noarch.rpm
  38. yum-utils-1.1.31-42.el7.noarch.rpm
  39. repodata
  40. 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目录下),并解压

  1. # mkdir -p /home/docker/local (如果不存在此目录,则创建,然后copy docker-local.tar.gz到此目录)
  2. # cd /home/docker/local
  3. # tar -zxvf docker-local.tar.gz

5 安装createrepo

  1. # cd /home/docker/local
  2. # rpm -ivh createrepo-0.9.9-28.el7.noarch.rpm (这个rpm安装包就是上面我们离线下载的安装包)

6 备份安装源

  1. # cd /etc/yum.repos.d/
  2. # mkdir repobak
  3. # mv * repobak/

7 配置离线安装源

  1. # vi /etc/yum.repos.d/docker-ce-local.repo
  2. [docker]
  3. name=docker local
  4. baseurl=file:///home/docker/local/
  5. gpgcheck=0
  6. enabled=1
  7. 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.检查是否安装成功

  1. # systemctl start docker
  2. # docker version
  3. Client:
  4.  Version:    18.03.0-ce
  5.  API version:    1.37
  6.  Go version:    go1.9.4
  7.  Git commit:    0520e24
  8.  Built:    Wed Mar 21 23:09:15 2018
  9.  OS/Arch:    linux/amd64
  10.  Experimental:    false
  11.  Orchestrator:    swarm
  12.  
  13. Server:
  14.  Engine:
  15.   Version:    18.03.0-ce
  16.   API version:    1.37 (minimum version 1.12)
  17.   Go version:    go1.9.4
  18.   Git commit:    0520e24
  19.   Built:    Wed Mar 21 23:13:03 2018
  20.   OS/Arch:    linux/amd64
  21.   Experimental:    false

12. 创建docker用户组

12.1 创建docker用户组

     # groupadd docker

12.2 将指定用户(比如ittest)加入docker用户组

     # usermod -aG docker  ittest

12.3 重启docker

     # systemctl restart docker