020_安装Docker
作者:互联网
安装Docker
环境准备
:::info
环境查看
[admin@ecs-214025 ~]$ uname -r
3.10.0-1160.62.1.el7.x86_64
:::info
命名规则:
主版本号:3
次版本号:10【奇数为开发版本,偶数为稳定版本】
修订版本号:0【修改的次数】
此次版本的第N次修改:957
el7:redhat enterprise linux 7
x86_64:编译框架(64位)
:::
[admin@ecs-214025 ~]$ cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
[admin@ecs-214025 ~]$ 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"
安装
安装文档
docker官网:https://www.docker.com/
docker文档:https://docs.docker.com/
卸载旧版本
[root@ecs-214025 admin]# yum remove docker \
> docker-client \
> docker-client-latest \
> docker-common \
> docker-latest \
> docker-latest-logrotate \
> docker-logrotate \
> docker-engine
Loaded plugins: fastestmirror
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
[root@ecs-214025 admin]#
安装yum-utils包
[root@ecs-214025 admin]# yum install -y yum-utils
Loaded plugins: fastestmirror
Determining fastest mirrors
base | 3.6 kB 00:00:00
epel
Dependency Installed:
python-chardet.noarch 0:2.2.1-3.el7 python-kitchen.noarch 0:1.1.1-5.el7
Complete!
[root@ecs-214025 admin]#
设置Docker镜像仓库
:::info
默认是国外的,非常慢,不要用,使用国内的
yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo
阿里云镜像地址:https://developer.aliyun.com/mirror/docker-ce?spm=a2c6h.13651102.0.0.19711b11Ug2qJo
yum-config-manager \ --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
:::
[root@ecs-214025 admin]# yum-config-manager \ --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@ecs-214025 admin]#
更新yum软件包索引
[root@ecs-214025 admin]# yum makecache fast
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
nginx | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/4): docker-ce-stable/7/x86_64/updateinfo | 55 B 00:00:00
(2/4): docker-ce-stable/7/x86_64/primary_db | 80 kB 00:00:00
(3/4): epel/x86_64/updateinfo | 1.0 MB 00:00:01
(4/4): epel/x86_64/primary_db | 7.0 MB 00:00:02
Metadata Cache Created
[root@ecs-214025 admin]#
安装docker引擎
:::info
docker-ce 社区版 ee 企业版
:::
[root@ecs-214025 admin]# yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package containerd.io.x86_64 0:1.6.6-3.1.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: containerd.io-1.6.6-3.1.el7.x86_64
---> Package docker-ce.x86_64 3:20.10.17-3.el7 will be installed
Dependency Installed:
audit-libs-python.x86_64 0:2.8.5-4.el7 checkpolicy.x86_64 0:2.5-8.el7 container-selinux.noarch 2:2.119.2-1.911c772.el7_8 docker-ce-rootless-extras.x86_64 0:20.10.17-3.el7
docker-scan-plugin.x86_64 0:0.17.0-3.el7 fuse-overlayfs.x86_64 0:0.7.2-6.el7_8 fuse3-libs.x86_64 0:3.6.1-4.el7 libcgroup.x86_64 0:0.41-21.el7
libsemanage-python.x86_64 0:2.5-14.el7 policycoreutils-python.x86_64 0:2.5-34.el7 python-IPy.noarch 0:0.75-6.el7 setools-libs.x86_64 0:3.3.8-4.el7
slirp4netns.x86_64 0:0.4.3-4.el7_8
Complete!
[root@ecs-214025 admin]#
启动docker
[root@ecs-214025 admin]# systemctl start docker
[root@ecs-214025 admin]#
查看docker版本
[root@ecs-214025 admin]# docker version
Client: Docker Engine - Community
Version: 20.10.17
API version: 1.41
Go version: go1.17.11
Git commit: 100c701
Built: Mon Jun 6 23:05:12 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.17
API version: 1.41 (minimum version 1.12)
Go version: go1.17.11
Git commit: a89b842
Built: Mon Jun 6 23:03:33 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.6
GitCommit: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
runc:
Version: 1.1.2
GitCommit: v1.1.2-0-ga916309
docker-init:
Version: 0.19.0
GitCommit: de40ad0
[root@ecs-214025 admin]#
运行hello-world镜像,验证Docker引擎是否已正确安装
[root@ecs-214025 admin]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:13e367d31ae85359f42d637adf6da428f76d75dc9afeb3c21faea0d976f5c651
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/
[root@ecs-214025 admin]#
查看docker所有镜像
[root@ecs-214025 admin]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 8 months ago 13.3kB
[root@ecs-214025 admin]#
卸载Docker
卸载 Docker Engine、CLI、Containerd 和 Docker Compose 软件包
yum remove docker-ce docker-ce-cli containerd.io docker-compose-plugin
主机上的映像、容器、卷或自定义配置文件不会自动删除。要删除所有映像、容器和卷
rm -rf /var/lib/docker
rm -rf /var/lib/containerd
手动删除任何已编辑的配置文件
docker run hello-world运行原理
底层原理
docker是怎么工作的?
:::info
Docker是一个Client-Server结构的系统,Docker的守护进程运行在主机上,通过Socket从客户端访问。
DockerServer接收到DockerClient的指令,就会执行这个命令。
:::
Docker为什么比VM快?
- Docker有着比虚拟机更少的抽象层。
- Docker利用的是宿主机的内核,VM需要Guest OS。
所以说,新建一个容器的时候,Docket不需要像虚拟机一样重新加载一个操作系统内核,避免引导。虚拟机是加载Guest OS,分钟级的,而Docker是利用宿主机的操作系统,省略了这个复杂的过程,是秒级的。
配置阿里云镜像加速
登录阿里云找到容器服务
找到镜像加速地址
配置使用
标签:00,ce,214025,ecs,020,docker,安装,Docker 来源: https://www.cnblogs.com/wl3pb/p/16439856.html