【CentOS】安装Docker教程

前提条件

Docker 运行在 CentOS 7 上,要求系统为64位、系统内核版本为 3.10 以上。

Docker 运行在 CentOS-6.5 或更高的版本的 CentOS 上,要求系统为64位、系统内核版本为 2.6.32-431 或者更高版本。

 

首先, 查看系统是否支持:

               image

 

Docker有两种方式安装:

  1. 脚本安装
  2. Yum包安装

 

安装前注意:

  1. 本文针对CentOS 7 去安装
  2. 如果太久或者是特殊系统不要yum update
  3. 必需要root权限

 

一、Yum包安装

(1) 添加 docker,Yum源
[root@localhost ~]# sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'
> [dockerrepo]
> name=Docker Repository
> baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/
> enabled=1
> gpgcheck=1
> gpgkey=https://yum.dockerproject.org/gpg
> EOF
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
(2) 安装 docker包
[root@localhost ~]# yum install docker-engine
(3) 启动守护 docker进程
[root@localhost ~]# service docker start
Redirecting to /bin/systemctl start  docker.service
(4) 测试
[root@localhost ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete 
Digest: sha256:97ce6fa4b6cdc0790cda65fe7290b74cfebd9fa0c9b8c38e979330d547d22ce1
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.
    (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://cloud.docker.com/

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

 

(5) 镜像加速 (可选)
 vim /etc/docker/daemon.json

{
  "registry-mirrors": ["http://hub-mirror.c.163.com"]
}
(6) 开机启动
[root@localhost ~]# systemctl enable docker.service

 

二、脚本安装 (感觉不太靠谱, 不推荐)

(1)  yum update

(2)  curl -sSL https://get.docker.com/ | sh

(3)  service docker start

(4)  docker run hello-world

 

启动时候会出现的错误:

  Job for docker.service failed. See 'systemctl status docker.service' and 'journalctl -xn' for details.

1: 防火墙之类的,

2: yum -y install docker

 

推荐文档:

http://www.runoob.com/docker/centos-docker-install.html

http://www.docker.org.cn/book/install/supported-platform-17.html

posted @ 2018-04-11 17:12  Eddie.Lee  阅读(524)  评论(0编辑  收藏  举报