安裝Docker
環(huán)境準(zhǔn)備
- CentOS7
環(huán)境查看
#系統(tǒng)內(nèi)核是3.10以上
[root@VM_0_8_centos ~]# uname -r
3.10.0-862.el7.x86_64
#系統(tǒng)版本
[root@VM_0_8_centos ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
安裝
查看官方文檔:https://docs.docker.com/engine/install/centos/
#1. 卸載舊版本
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
#2.安裝需要的包
$ sudo yum install -y yum-utils
#3.設(shè)置鏡像倉庫(使用國內(nèi)阿里云)
$ sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#4.更新yum軟件包索引
[root@VM_0_8_centos ~]# yum makecache fast
#5.安裝Docker 相關(guān)源(最新)
$ sudo yum install docker-ce docker-ce-cli containerd.io
#6.啟動(dòng)docker
$ sudo systemctl start docker
#7.查看Docker
[root@VM_0_8_centos ~]# docker version
Client: Docker Engine - Community
Version: 19.03.13
API version: 1.40
Go version: go1.13.15
Git commit: 4484c46d9d
Built: Wed Sep 16 17:03:45 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.13
API version: 1.40 (minimum version 1.12)
Go version: go1.13.15
Git commit: 4484c46d9d
Built: Wed Sep 16 17:02:21 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.3.7
GitCommit: 8fba4e9a7d01810a393d5d25a3621dc101981175
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
#8. 運(yùn)行docker hello-world示例 (首次執(zhí)行會(huì)下載)
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:4cf9c47f86df71d48364001ede3a4fcd85ae80ce02ebad74156906caff5378bc
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/
#9.查看鏡像
[root@VM_0_8_centos ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest bf756fb1ae65 9 months ago 13.3kB
最后一步留攒,出現(xiàn) Hello from Docker! 表示Docker安裝完成!
卸載Docker
#1.卸載安裝包
$ sudo yum remove docker-ce docker-ce-cli containerd.io
#2.卸載默認(rèn)工作路徑
$ sudo rm -rf /var/lib/docker