LEN

Contos7 Docker 安装
今天放假没活动,在家研究下Docker , 诶 知道Docker 很久了,但是一直也没安装成功.原因有很多,因为之...
扫描右侧二维码阅读全文
15
2017/01

Contos7 Docker 安装

今天放假没活动,在家研究下Docker , 诶 知道Docker 很久了,但是一直也没安装成功.
原因有很多,因为之前使用centos 都是低版本,安装Docker 存在很多的环境依赖问题太多了;

根据官网给出的安装教程, 开始安装:
首先需要根据操作系统选择对应安装版本, 本文使用 centos 7 操作系统 搭建在虚拟机中;

1.查看 内核发行号

系统要求

Docker 最低支持 CentOS 7

Docker 需要安装在 64 位的平台,并且内核版本不低于 3.10 CentOS 7 满足最低内核的要求,但由于内核版本比较低,部分功能(如 overlay2 存储层驱动)无法使用,并且部分功能可能不太稳定。

[root@localhost ~]# uname -r
3.10.0-327.el7.x86_64

内核ok后,最好将依赖都更新一遍

[root@localhost ~]# yum update 


教程上使用 tee /etc/yum.repos.d/docker.repo 写入文件

[root@localhost ~]# yum install tree
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net
 * extras: mirrors.neusoft.edu.cn
 * updates: mirrors.neusoft.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================
 Package                    Arch                         Version                               Repository
=========================================================================================================
Installing:
 tree                       x86_64                       1.6.0-10.el7                          base      

Transaction Summary
=========================================================================================================
Install  1 Package

Total download size: 46 k
Installed size: 87 k
Is this ok [y/d/N]: y
Downloading packages:
tree-1.6.0-10.el7.x86_64.rpm                                                                             
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : tree-1.6.0-10.el7.x86_64                                                                  
  Verifying  : tree-1.6.0-10.el7.x86_64                                                                  

Installed:
  tree.x86_64 0:1.6.0-10.el7                                                                             

Complete!

2. 添加 yum 源

虽然 CentOS 软件源 Extras 中有 Docker,名为 docker,但是不建议使用系统源中的这个版本,它的版本相对比较陈旧,而且并非 Docker 官方维护的版本。因此,我们需要使用 Docker 官方提供的 CentOS 软件源。

执行下面的命令添加 yum 软件源。

[root@localhost ~]# tee /etc/yum.repos.d/docker.repo <<-'EOF'
> [dockerrepo]
> name=Docker Repository
> baseurl=https://yum.dockerproject.org/repo/main/centos/7/
> enabled=1
> gpgcheck=1
> gpgkey=https://yum.dockerproject.org/gpg
> EOF
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg

3. 安装Docker 软件包

[root@localhost yum.repos.d]# sudo yum install docker-engine
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net
 * extras: mirrors.neusoft.edu.cn
 * updates: mirrors.neusoft.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package docker-engine.x86_64 0:1.12.6-1.el7.centos will be installed
--> Processing Dependency: docker-engine-selinux >= 1.12.6-1.el7.centos for package: docker-engine-1.12.6
--> Running transaction check
---> Package docker-engine-selinux.noarch 0:1.12.6-1.el7.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================
 Package                              Arch                  Version                             Repositor
=========================================================================================================
Installing:
 docker-engine                        x86_64                1.12.6-1.el7.centos                 dockerrep
Installing for dependencies:
 docker-engine-selinux                noarch                1.12.6-1.el7.centos                 dockerrep

Transaction Summary
=========================================================================================================
Install  1 Package (+1 Dependent package)

Total size: 19 M
Installed size: 79 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/dockerrepo/packages/docker-engine-1.12.6-1.el7.centos.x86_64.rpm: Headere, key ID 2c52609d: NOKEY
Retrieving key from https://yum.dockerproject.org/gpg
Importing GPG key 0x2C52609D:
 Userid     : "Docker Release Tool (releasedocker) <docker@docker.com>"
 Fingerprint: 5811 8e89 f3a9 1289 7c07 0adb f762 2157 2c52 609d
 From       : https://yum.dockerproject.org/gpg
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : docker-engine-selinux-1.12.6-1.el7.centos.noarch                                          
Re-declaration of boolean virt_sandbox_use_fusefs
Failed to create node
Bad boolean declaration at /etc/selinux/targeted/tmp/modules/100/virt/cil:159
/usr/sbin/semodule:  Failed!
libsemanage.semanage_direct_install_info: Overriding docker module at lower priority 100 with module at p
restorecon:  lstat(/var/lib/docker) failed:  No such file or directory
warning: %post(docker-engine-selinux-1.12.6-1.el7.centos.noarch) scriptlet failed, exit status 255
Non-fatal POSTIN scriptlet failure in rpm package docker-engine-selinux-1.12.6-1.el7.centos.noarch
  Installing : docker-engine-1.12.6-1.el7.centos.x86_64                                                  
  Verifying  : docker-engine-1.12.6-1.el7.centos.x86_64                                                  
  Verifying  : docker-engine-selinux-1.12.6-1.el7.centos.noarch                                          

Installed:
  docker-engine.x86_64 0:1.12.6-1.el7.centos                                                             

Dependency Installed:
  docker-engine-selinux.noarch 0:1.12.6-1.el7.centos                                                     

Complete!

4. 启动服务

这个服务启动 没弄明白 什么意思 目前理解是 启动docker 服务 但下面还需要启动docker 进程

[root@localhost yum.repos.d]# systemctl enable docker.service
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

5. 开始Docker守护

[root@localhost ~]# systemctl start docker

6. Verify docker is installed correctly by running a test image in a container.

这个段英文 有道翻译的 我就看个大概意思 就是验证下容器

[root@localhost ~]# docker run --rm hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
78445dd45222: Pull complete 
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
Status: Downloaded newer image for hello-world:latest

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.
 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://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

7. 建立 docker 用户组

默认情况下,docker 命令会使用 Unix socket 与 Docker 引擎通讯。而只有 root 用户和 docker 组的用户才可以访问 Docker 引擎的 Unix socket。出于安全考虑,一般 Linux 系统上不会直接使用 root 用户。因此,更好地做法是将需要使用 docker 的用户加入 docker 用户组。

建立 docker 组:

$ sudo groupadd docker

将当前用户加入 docker 组:

$ sudo usermod -aG docker $USER

官方实际上提供了两种安装方式
上面安装 docker 的方法是使用 yum 包 进行安装
还有一种是使用脚本
使用 shell 脚本安装
脚本内容 可以找下

$ curl -fsSL https://get.docker.com/ | sh

参考资料 : Docker 入门到实践


参考官方文档 : https://docs.docker.com/engine/installation/linux/centos/

Last modification:February 8th, 2017 at 02:49 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment