centos7.5 安装指定版本docker

centos7.5 安装指定版本docker

安装docker

设置仓库
  1. 安装所需包

    [root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
    
  2. 设置docker仓库

    [root@localhost ~]# yum-config-manager \
            --add-repo \
            https://download.docker.com/linux/centos/docker-ce.repo
    
安装docker ce
  1. 显示可用资源

    [root@localhost ~]# yum list docker-ce --showduplicates |sort -r
    
  2. 安装指定版本

    [root@localhost ~]# yum install -y docker-ce-18.06.1.ce-3.el7
    
配置docker启动
  1. 配置国内镜像,增加配置文件daemon.json

    [root@localhost ~]# mkdir -p /etc/docker
    [root@localhost ~]# cat /etc/docker/daemon.json
    {
      "registry-mirrors" : [
        "http://ovfftd6p.mirror.aliyuncs.com",
        "http://registry.docker-cn.com",
        "http://docker.mirrors.ustc.edu.cn",
        "http://hub-mirror.c.163.com"
      ],
      "insecure-registries" : [
        "registry.docker-cn.com",
        "docker.mirrors.ustc.edu.cn"
      ],
      "debug" : true,
      "experimental" : true
    }
    
  2. 服务开机自启,启动服务

    [root@localhost ~]# systemctl enable docker
    [root@localhost ~]# systemctl start docker
    [root@localhost ~]# docker version
    Client:
     Version:           18.06.1-ce
     API version:       1.38
     Go version:        go1.10.3
     Git commit:        e68fc7a
     Built:             Tue Aug 21 17:23:03 2018
     OS/Arch:           linux/amd64
     Experimental:      false
    
    Server:
     Engine:
      Version:          18.06.1-ce
      API version:      1.38 (minimum version 1.12)
      Go version:       go1.10.3
      Git commit:       e68fc7a
      Built:            Tue Aug 21 17:25:29 2018
      OS/Arch:          linux/amd64
      Experimental:     false
    
启动基础镜像

启动官方centos7镜像

[root@localhost ~]# docker run -d -it --cpus=4 --cpuset-cpus=0-3 -p 80:80 -p 443:443 -p 514:514 -p 3601:3601 -p 3602:3602 -p 3603:3603 -p 3604:3604 -p 3605:3605 -p 3606:3606 --shm-size=2048m --privileged --name centos7-test -v /home:/media -v /sys/fs/cgroup:/sys/fs/cgroup centos:centos7.5.1804 /usr/sbin/init

遇到的问题

  1. esxi 快照恢复后,docker内网络不可达

    解决办法:
    # vi /etc/sysctl.conf
    或者
    # vi /usr/lib/sysctl.d/00-system.conf
    
    添加如下代码:
        net.ipv4.ip_forward=1
    重启network服务
    # systemctl restart network
    
    查看是否修改成功
    # sysctl net.ipv4.ip_forward
    
  2. 依赖缺失

    yum install --downloadonly --downloaddir=./ net-tools
    yum install --downloadonly --downloaddir=./ lspci
    yum install --downloadonly --downloaddir=./ pciutils
    yum install --downloadonly --downloaddir=./ sysvinit-tools
    yum install --downloadonly --downloaddir=/media/rpm-source dmidecode
    yum install --downloadonly --downloaddir=/media/rpm-source openssh-server openssh-clients
    yum install --downloadonly --downloaddir=/media/rpm-source iptables
    
  3. 修改启动脚本

    /script/start.sh: line 132: /sys/kernel/mm/redhat_transparent_hugepage/enabled: No such file or directory
    /script/start.sh: line 133: /sys/kernel/mm/redhat_transparent_hugepage/defrag: No such file or directory
    
    /sys/kernel/mm/transparent_hugepage/enabled
    /sys/kernel/mm/transparent_hugepage/defrag
    
  4. pip 安装存在问题

    # pip install XXX 异常
    # 重新网络安装pip
    Installing collected packages: pycparser, cffi
    Successfully installed cffi-1.13.2 pycparser-2.19
    Exception:
    Traceback (most recent call last):
      File "/usr/local/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py", line 215, in main
        status = self.run(options, args)
      File "/usr/local/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/install.py", line 312, in run
        wheel_cache
      File "/usr/local/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py", line 295, in populate_requirement_set
        wheel_cache=wheel_cache):
      File "/usr/local/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_file.py", line 84, in parse_requirements
        filename, comes_from=comes_from, session=session
      File "/usr/local/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/download.py", line 422, in get_file_content
        content = auto_decode(f.read())
      File "/usr/local/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/encoding.py", line 31, in auto_decode
        return data.decode(locale.getpreferredencoding(False))
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xe8 in position 2: ordinal not in range(128)
    
    # pip安装依赖包,又遇到著名的python ascii codec cant decode byte错误
    # 原因: 系统当前语言为空,local为空, echo $LANG 为空
    # 解决 在执行pip install 前增加 export LANG="en_US.UTF-8"
    
  5. docker image centos7 无法使用systemctl

    # 在创建CentOS7容器时,使用 systemctl start 启动某个服务可能会出现如下错误 :
    # Failed to get D-Bus connection: Operation not permitted
    
    # 需要给容器提权添加 --privileged 参数,并将 cmd 或者 entrypoint 设置为 /usr/sbin/init
    [root@localhost ~]# docker run --privileged -itd --name=test -v /sys/fs/cgroup:/sys/fs/cgroup  centos  /usr/sbin/init    ## 启动一个后台容器
    [root@localhost ~]# docker exec -it test /bin/bash    ## 使用命令行进入容器
    
  6. docker file

    dockerfile 增加
    
    ENV LANG en_US.UTF-8
    ENV LC_ALL en_US.UTF-8
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值