目前Docker支持centos 7及以后版本。
本文中使用的是centos7系统。
安装所需的软件包
$ sudo yum install update $ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
设置稳定的仓库
官方源
$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
有时由于网络问题,无法访问官方源,也可以添加国内源:
$ sudo yum-config-manager \ --add-repo \ https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo
安装docker
$ sudo yum install docker-ce
安装过程中,也会将docker-ce-cli, containerd.io 作为依赖进行安装。
启动docker
sudo systemctl start docker
查看docker进程是否已经启动:
$ ps -ef| grep docker root 12486 1 0 23:21 ? 00:00:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock lanyang 12639 10783 0 23:21 pts/0 00:00:00 grep --color=auto docker
查看docker版本信息:
[lanyang@localhost ~]$ sudo docker version Client: Docker Engine - Community Version: 19.03.5 API version: 1.40 Go version: go1.12.12 Git commit: 633a0ea Built: Wed Nov 13 07:25:41 2019 OS/Arch: linux/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 19.03.5 API version: 1.40 (minimum version 1.12) Go version: go1.12.12 Git commit: 633a0ea Built: Wed Nov 13 07:24:18 2019 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.2.10 GitCommit: b34a5c8af56e510852c35414db4c1f4fa6172339 runc: Version: 1.0.0-rc8+dev GitCommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657 docker-init: Version: 0.18.0 GitCommit: fec3683
通过运行 hello-world 映像来验证是否正确安装了 Docker Engine-Community
[lanyang@localhost ~]$ sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Already exists Digest: sha256:9572f7cdcee8591948c2963463447a53466950b3fc15a247fcad1917ca215a2f 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://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/
上面的输出,表示docker已经安装成功。
执行hello-world的过程如下:.
- Docker client连接 Docker daemon, 将请求发送给Docker daemon。
- Docker daemon 从Docker Hub拉取"hello-world"映像。
- Docker daemon 使用拉取的映像,创建一个新的容器,在容器中执行可执行文件,并得到输出。
- Docker daemon 将输出发给Docker client,Docker client再请输出发送到终端显示。
来源:https://www.cnblogs.com/lanyangsh/p/12244956.html