Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从 Apache2.0 协议开源。

  Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。

  容器是完全使用沙箱机制,相互之间不会有任何接口(类似 iPhone 的 app),更重要的是容器性能开销极低。

目录

Centos7安装Docker

安装准备

Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的CentOS 版本是否支持 Docker,通过 uname -r 命令查看你当前的内核版本

1
$ uname -r

较旧的Docker版本称为docker或docker-engine。如果已安装这些程序,请卸载它们以及相关的依赖项。

1
2
3
4
5
6
7
8
$ yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

yum安装

安装需要的软件包,yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的

1
$ yum install -y yum-utils device-mapper-persistent-data lvm2

设置yum源

1
2
3
$ yum-config-manager \
    --add-repo \
    //download.docker.com/linux/centos/docker-ce.repo

可以查看所有仓库中所有docker版本,并选择特定版本安装

1
2
3
4
5
$ yum list docker-ce --showduplicates | sort -r
docker-ce.x86_64  3:18.09.1-3.el7                     docker-ce-stable
docker-ce.x86_64  3:18.09.0-3.el7                     docker-ce-stable
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 Engine-Community和containerd

1
$ yum install docker-ce docker-ce-cli containerd.io

启动并加入开机启动

1
2
$ systemctl start docker
$ systemctl enable docker

编译安装

下载对应的安装包

1
$ wget https://download.docker.com/linux/static/stable/x86_64/docker-19.03.2.tgz

解压包

1
$ tar xzvf docker-19.03.2.tgz

添加命令执行路径

1
$ cp docker/* /usr/bin/

启动Docker守护进程

1
$ dockerd &

验证安装

通过运行hello-world 映像来验证是否正确安装了Docker Engine-Community,此命令下载测试图像并在容器中运行。容器运行时,它会打印参考消息并退出。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
$ 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:
 //hub.docker.com/

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