Docker
安装在Linux(CentOS 8)上的步骤
先查看系统自带的 docker 镜像
-- [root@xoste /]# uname -r
4.18.0-147.5.1.el8_1.x86_64
查看系统的相关信息
-- [root@xoste /]# cat /etc/os-release
NAME="CentOS Linux" VERSION="8 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="8" PLATFORM_ID="platform:el8" PRETTY_NAME="CentOS Linux 8 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:8" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-8"
CENTOS_MANTISBT_PROJECT_VERSION="8"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="8"
移除系统自带的 docker 镜像
-- [root@xoste /]# yum remove docker
docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine No match for argument: docker No match for argument: docker-client No match for argument: docker-client-latest No match for argument: docker-common No match for argument: docker-latest No match for argument: docker-latest-logrotate No match for argument: docker-logrotate No match for argument: docker-engine No packages marked for removal. Dependencies resolved. Nothing to do. Complete!
安装 docker 运行环境
-- [root@xoste /]# yum install -y yum-utils
Last metadata expiration check: 0:05:28 ago on Thu 15 Jul 2021 06:51:38 PM CST. Dependencies resolved. ...
安装 docker 的配置管理(使用的是阿里云的 CentOS 的 docker-ce 镜像
-- [root@xoste /]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
更新 yum 软件包索引(如果没用不用管,直接往下)
-- [root@xoste /]# yum makecache faster
安装 docker 的核心(引擎)docker-ce(社区) docker-ee(企业)
-- [root@xoste /]# yum install docker-ce docker-ce-cli containerd.io
Docker CE Stable - x86_64 58 kB/s | 14 kB 00:00 Dependencies resolved.
...
y/n y
启动 docker
-- [root@xoste /]# systemctl start docker
检查 docker 是否启动成功
-- [root@xoste /]# docker version
Client: Docker Engine - Community Version: 20.10.7 API version: 1.41 Go version: go1.13.15 Git commit: f0df350 Built: Wed Jun 2 11:56:24 2021 OS/Arch: linux/amd64 Context: default Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.7
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: b0f5bc3
Built: Wed Jun 2 11:54:48 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.6
GitCommit: d71fcd7d8303cbf684402823e425e9dd2e99285d
runc:
Version: 1.0.0-rc95
GitCommit: b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
docker-init:
Version: 0.19.0
GitCommit: de40ad
测试 hello world (如果这步有问题,继续往下执行,否则成功)
-- [root@xoste docker]# docker run hello-world
Unable to find image 'hello-world:latest' locally
测试 hello world 失败,到 docker 文件下找 daemon.json,如果没有,创建一个(这步嫌麻烦,可以直接跳到最后一步,红色部分直接全部复制,粘贴运行,就可)
cd /etc/docker 有 key.json 和 daemon.json 两个文件
-- [root@xoste docker]# sudo touch daemon.json
[root@xoste docker]# chmod 777 daemon.json
[root@xoste docker]# vim daemon.json
[root@xoste docker]# systemctl restart docker
[root@xoste docker]# docker versioin
[root@xoste docker]# docker run hello-world
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world b8dfde127a29: Pull complete Digest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e 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/
查看一下下载的这个 hello-world 镜像
-- [root@xoste docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest d1165f221234 4 months ago 13.3kB
了解:卸载 docker
-- yum remove docker-ce docker-ce-cli containerd.io
rm -rf /var/lib/docker #docker 的默认工作路径!
rm -rf /var/lib/containerd
配置镜像加速器(红色部分直接全部复制,粘贴运行,就可)
-- sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://aiz54qaa.mirror.aliyuncs.com"] } EOF
sudo systemctl daemon-reload
sudo systemctl restart docker