码迷,mamicode.com
首页 > 其他好文 > 详细

Centos 7.5 docker ( 一 ) 安装

时间:2018-11-02 20:28:12      阅读:296      评论:0      收藏:0      [点我收藏+]

标签:ash   lvm   相关   workflow   and   类型   fir   系统环境   mct   

系统环境
阿里云ECS
# uname -r
4.4.162-1.el7.elrepo.x86_64

# cat /etc/centos-release
CentOS Linux release 7.5.1804 (Core)

# rpm -qa |grep kernel
kernel-lt-tools-libs-4.4.162-1.el7.elrepo.x86_64
kernel-lt-4.4.162-1.el7.elrepo.x86_64
kernel-lt-headers-4.4.162-1.el7.elrepo.x86_64
kernel-lt-devel-4.4.162-1.el7.elrepo.x86_64
kernel-lt-tools-4.4.162-1.el7.elrepo.x86_64

安装Docker ce

官方文档有详细操作,可以参考
https://docs.docker.com/install/linux/docker-ce/centos/

通过yum安装

卸载旧版本(按需)

如果有旧版本docker,请使用以下指令卸载
# yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine

安装依赖

# yum install yum-utils device-mapper-persistent-data lvm2

docker 版本说明

Docker CE有两种版本:
edge        版本每月发布一次,主要面向那些喜欢尝试新功能的用户。
stable      版本每3个月发布一次,维护期4个月。适用于希望更加容易维护的用户(稳定版)。

edge版本    只能在当前月份获得安全和错误修复。
stable版    在初始发布后4个月内接收关键错误修复和安全问题的修补程序。
Docker EE和stable版本的版本号保持一致。CE版并非阉割版,而是改了个名称;EE版则提供了一些收费的高级特性。

添加docker ce的yum源(按需选择其一)

stable 版本
# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

edge 版本
如果需要edge版本的docker,在上一条指令成功后启用下面一行命令
# yum-config-manager --enable docker-ce-edge

方式一: 直接安装最新版本版本

# yum install docker-ce

方式二: 安装指定版本

列出版本
# yum list docker-ce --showduplicates | sort -r
 * elrepo: mirrors.tuna.tsinghua.edu.cn
docker-ce.x86_64            18.06.1.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.06.0.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            18.03.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.3.ce-1.el7                    docker-ce-stable
docker-ce.x86_64            17.03.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.0.ce-1.el7.centos             docker-ce-stable
Available Packages

语法 yum install docker-ce-<版本号>
示例:
# yum install docker-ce-17.12.0.ce-1.el7.centos
# yum install docker-ce-18.06.1.ce-3.el7

添加国内镜像源

在国内下载比较快

Docker 官方中国区
https://registry.docker-cn.com

网易
http://hub-mirror.c.163.com

中国科学技术大学
https://docker.mirrors.ustc.edu.cn

阿里云
https://dev.aliyun.com/
注册登陆账号后,左边菜单选 > 镜像加速器 > 获取到以下累似地址(当然,你也可以直接使用我的)
https://314lfirc.mirror.aliyuncs.com

最新版本的docker官方建议使用json格式修改

# vim /etc/docker/daemon.json

{
  "registry-mirrors": ["https://314lfirc.mirror.aliyuncs.com"],
  "live-restore": true,
  "default-shm-size": "128M",
  "max-concurrent-downloads": 10,
  "oom-score-adjust": -1000,
  "debug": false
}

启动Docker与设置开机启动docker

# systemctl start docker
# systemctl enable docker

验证

方法一:

# 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

方法二:

# docker info

会出现类似下面的相关信息
#docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 18.06.1-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 468a545b9edcd5932818eb9de8e72413e616e86e
runc version: 69663f0bd4b60df09991c08812a60108003fa340
init version: fec3683
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.4.162-1.el7.elrepo.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 3.859GiB
Name: jumpserver01
ID: 7V2P:3XOE:7IZD:V5FH:5IME:WMQ6:CGJH:7A3Y:7SUM:RKPJ:27C6:34GY
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Registry Mirrors:
 https://314lfirc.mirror.aliyuncs.com/        > 这里是添加的加速器
Live Restore Enabled: true

方法三:

通过运行hello-world 映像验证是否已正确安装,
# docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

docker-compose 命令补全

1. 安装docker-compose
# pip install docker-compose
# pip install --upgrade pip 这一行指令是升级pip版本的,按需。

2.找到对应当前compose版本号的命令补全
# docker-compose version
/usr/lib/python2.7/site-packages/requests/__init__.py:80: RequestsDependencyWarning: urllib3 (1.22) or chardet (2.2.1) doesn‘t match a supported version!
  RequestsDependencyWarning)
docker-compose version 1.23.1, build b02f130  这次安装的版本号是1.23.1
docker-py version: 3.5.1
CPython version: 2.7.5
OpenSSL version: OpenSSL 1.0.2k-fips  26 Jan 2017

有留意到吧,查看  docker-compose 的version时报不兼容的问题
解决它:
# pip uninstall urllib3 chardet

Uninstalling chardet-3.0.4:
  Would remove:
    /usr/bin/chardetect
    /usr/lib/python2.7/site-packages/chardet-3.0.4.dist-info/*
    /usr/lib/python2.7/site-packages/chardet/*
  Would not remove (might be manually added):
    /usr/lib/python2.7/site-packages/chardet/chardetect.py
    /usr/lib/python2.7/site-packages/chardet/chardetect.pyo
    /usr/lib/python2.7/site-packages/chardet/constants.py
    /usr/lib/python2.7/site-packages/chardet/constants.pyo
Proceed (y/n)? y
  Successfully uninstalled chardet-3.0.4
Uninstalling urllib3-1.22:
  Would remove:
    /usr/lib/python2.7/site-packages/urllib3-1.22.dist-info/*
    /usr/lib/python2.7/site-packages/urllib3/*
Proceed (y/n)? y
  Successfully uninstalled urllib3-1.22

重新安装
# pip install requests
Successfully installed chardet-3.0.4 urllib3-1.22

再执行就没问题了
# docker-compose version

docker-compose version 1.23.1, build b02f130
docker-py version: 3.5.1
CPython version: 2.7.5
OpenSSL version: OpenSSL 1.0.2k-fips  26 Jan 2017

3. 去https://github.com/docker/compose/
找到对应docker-compose版本的命令补全包

点开 Branch:master 边上的小倒三角,选Tags ,点中你的版本号
进入以下目录
compose/contrib/completion/这里是你喜欢的shell类型/docker-compose
点开这个文件,对着Raw复制下载地址(否则不对)

下载到系统中,
wget -O/etc/bash_completion.d/docker-compose https://raw.githubusercontent.com/docker/compose/1.23.1/contrib/completion/bash/docker-compose

生效当前shell
# exec bash

以非root用户身份管理Docker

在安装docker时,默认已经创建了docker用户组,该docker组授予与root 用户等效的权限。
# useradd -g docker docker
# passwd docker
设置这个普通用户密码

注销并重新登录,以便重新评估您的组成员身份。
如果在虚拟机上进行测试,则可能需要重新启动虚拟机才能使更改生效。
$ docker run hello-world
此命令下载测试映像并在容器中运行它。当容器运行时,它会打印一条信息性消息并退出

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

Centos 7.5 docker ( 一 ) 安装

标签:ash   lvm   相关   workflow   and   类型   fir   系统环境   mct   

原文地址:http://blog.51cto.com/191226139/2312241

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!