01 -- centos7 安装docker

说明:

官方提供了两种安装方式,yum和二进制安装包.考虑到生产机房环境内外网是隔离的,所以选择万能的二进制安装方式.虽然复杂一点,但是适用于所有的场景.

1. 安装前置检查条件

docker正常运行时需要以下三个软件安装成功

  • iptable1.4或更高版本
  • Git1.7或更高版本
  • procps(或 "ps" 可执行类似的提供程序)
  • XZ utils4.9或更高版本###Linux内核和安全检查
  • 内核必须是3.10版及以上
  • AppArmor 和 SELinux 在默认开启的情况下会阻止Docker运行,请关闭或者为Docker配置安全策略
    centos 关闭SELinux:

临时关闭
setenforce 0
永久关闭,修改配置文件
vim /etc/selinux/config

#SELINUX=enforcing  注释掉此行,将其修改为disableSELINUX=disabled

2. 获得二进制安装程序

  • 下载最新的安装程序

https://get.docker.com/builds/Linux/i386/docker-latest.tgz
https://get.docker.com/builds/Linux/x86_64/docker-latest.tgz

  • 下载特定版本的安装程序

https://get.docker.com/builds/Linux/i386/docker-1.11.0.tgz
https://get.docker.com/builds/Linux/x86_64/docker-1.11.0.tgz

3. 解压安装

  • 下载后解压安装
#解压
tar -zxvf docker-latest.tgz
#将其移动到合适的目录下
mv ./docker /usr/local/docker
  • 加入到$PATH
vim /etc/profile
#----------------------------
#dockerexport 
DOCKER_HOME=/usr/local/dock
erexport PATH=$PATH:$DOCKER_HOME
#----------------------------
#刷新环境变量
source /etc/profile

4. 验证安装结果

  • 查看docker版本
#验证docker是否安装成功docker version
#输出如下
Client:
    Version:      1.12.3API 
    version:  1.24Go 
    version:  go1.6.3
    Git commit:  6b644ec
    Built:        Wed Oct 26 23:26:11 2016
    OS/Arch:      linux/amd64
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
  • 运行hello world
#启动docker
dockerd &
#运行命令(多试几次,由于网络原因,可能会出现timeout之类的错误),下载拉取并且运行一个hello-word容器
docker run 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 ps -a
#输入出如下
#---------------------------------------------------------------------------------------------------------------------------------------------#
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES
1063401ec028        hello-world         "/hello"            7 minutes ago       Exited (0) 7 minutes ago                       ecstatic_yalow
#---------------------------------------------------------------------------------------------------------------------------------------------#

你可能感兴趣的:(01 -- centos7 安装docker)