Docker 第二篇--安装Docker

先决条件

  1. 64 bit的操作系统(笔者使用的是64 位的Centos ), 如果需要在32 Bit的机器上运行docker需要自行编译。
  2. Linux kernel必须是3.10及以上的版本。   
[root@master ~]# uname -r
3.10.0-514.2.2.el7.x86_64

安装Docker engine 

使用yum 进行安装, 先update一下:

sudo yum update

添加一个docker的yum源, 如果这里不添加而是使用默认的源的话很可能安装的不是最新版本的Docker:

$ sudo 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

接下来我们就要进行安装了

$ sudo yum install docker-engine

启用Docker服务

$ sudo systemctl enable docker.service

至此Docker的安装就已经完成了, 查看下Docker的版本:

[root@master ~]# docker version
Client:
 Version:      1.12.5
 API version:  1.24
 Go version:   go1.6.4
 Git commit:   7392c3b
 Built:        Fri Dec 16 02:23:59 2016
 OS/Arch:      linux/amd64

Server:
 Version:      1.12.5
 API version:  1.24
 Go version:   go1.6.4
 Git commit:   7392c3b
 Built:        Fri Dec 16 02:23:59 2016
 OS/Arch:      linux/amd64

我们安装的是最新的Docker 1.12.5的版本

接下来我们验证下Docker的安装是否成功, 还是从Hello-Word开始:

[root@master ~]# docker run --rm hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c04b14da8d14: Pull complete 
Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
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 Hub account:
 https://hub.docker.com

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

当你看到这样的输出就证明Docker已经安装成功并且运行了第一个application. 但是这里要重点说一下标绿的部分, 这个地方可以看到本地没有Image要从Docker Hub 下载相应的Image.

由于XX的关照, 我们是不能正常访问Docker Hub的, 需要配置一个代理。在Centos 7以前我们只需要在/etc/sysconfig/docker的配置文件中添加配置即可 ,但是Centos使用systemd来管理进程我们已经无法这样使用了。

下面我们看看如何在Centos 7里面给Docker配置代理:

  1. 创建Docker配置文件的目录

  mkdir /etc/systemd/system/docker.service.d

      2. 创建Http代理的配置文件

  touch /etc/systemd/system/docker.service.d/http-proxy.conf

      3.添加代理配置

  [Service]

      Environment="HTTP_PROXY=http://host:port"

      Environment="HTTPS_PROXY=https://host:port"

     4. 重启daemon和docker

      [root@master ~]# systemctl daemon-reload
  [root@master ~]# systemctl restart docker

     5. 确认代理是否添加成功

  [root@master ~]# systemctl show docker --property Environment
  Environment=HTTP_PROXY=http://host:port HTTPS_PROXY=https://host:port

在路上,不顾风雨兼程
原文地址:https://www.cnblogs.com/crazyyang/p/6263972.html