【Docker】Docker安装

news/2024/10/22 14:24:46/

Docker安装

Docker官网和仓库

docker官网:http://www.docker.com

Docker Hub(镜像仓库)官网:https://hub.docker.com/

前提说明

Docker必须部署在Linux内核的系统上,如果其他系统想部署Docker就必须安装一个虚拟Linux环境。

Docker镜像

Docker镜像Image是一个只读的模板,镜像可以用来创建Docker容器,一个镜像就可以创建很多容器。

它相当于一个root文件系统。

image文件生产的容器实例,本身是一个文件,称为镜像文件。

Docker仓库

仓库分为公开仓库(Public)和私有仓库(Private)两种形式。

最大的公开仓库就是上面的官网,存放了数量庞大的镜像供用户下载。国内的公开仓库包括阿里云、网易云等。

Docker整体架构和通信原理需要花时间理解。

安装过程(CentOS为例)

确定CentOS版本

[root@192 ~]# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)

卸载旧版本

Older versions of Docker went by the names of docker or docker-engine. Uninstall any such older versions before attempting to install a new version, along with associated dependencies:

sudo yum remove docker \docker-client \docker-client-latest \docker-common \docker-latest \docker-latest-logrotate \docker-logrotate \docker-engine

yum安装gcc相关

[root@192 ~]# yum -y install gcc
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile* base: mirrors.163.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com
Package gcc-4.8.5-44.el7.x86_64 already installed and latest version
Nothing to do[root@192 ~]# yum -y install gcc-c++
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile* base: mirrors.163.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package gcc-c++.x86_64 0:4.8.5-44.el7 will be installed
--> Processing Dependency: libstdc++-devel = 4.8.5-44.el7 for package: gcc-c++-4.8.5-44.el7.x86_64
--> Running transaction check
---> Package libstdc++-devel.x86_64 0:4.8.5-44.el7 will be installed
--> Finished Dependency ResolutionDependencies Resolved=============================================================================================================================================================================================Package                                            Arch                                      Version                                          Repository                               Size
=============================================================================================================================================================================================
Installing:gcc-c++                                            x86_64                                    4.8.5-44.el7                                     base                                    7.2 M
Installing for dependencies:libstdc++-devel                                    x86_64                                    4.8.5-44.el7                                     base                                    1.5 MTransaction Summary
=============================================================================================================================================================================================
Install  1 Package (+1 Dependent package)Total download size: 8.7 M
Installed size: 25 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/libstdc++-devel-4.8.5-44.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY             ]  0.0 B/s | 623 kB  --:--:-- ETA 
Public key for libstdc++-devel-4.8.5-44.el7.x86_64.rpm is not installed
(1/2): libstdc++-devel-4.8.5-44.el7.x86_64.rpm                                                                                                                        | 1.5 MB  00:00:00     
(2/2): gcc-c++-4.8.5-44.el7.x86_64.rpm                                                                                                                                | 7.2 MB  00:00:01     
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                        4.6 MB/s | 8.7 MB  00:00:01     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5Package    : centos-release-7-9.2009.0.el7.centos.x86_64 (@anaconda)From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transactionInstalling : libstdc++-devel-4.8.5-44.el7.x86_64                                                                                                                                       1/2 Installing : gcc-c++-4.8.5-44.el7.x86_64                                                                                                                                               2/2 Verifying  : gcc-c++-4.8.5-44.el7.x86_64                                                                                                                                               1/2 Verifying  : libstdc++-devel-4.8.5-44.el7.x86_64                                                                                                                                       2/2 Installed:gcc-c++.x86_64 0:4.8.5-44.el7                                                                                                                                                              Dependency Installed:libstdc++-devel.x86_64 0:4.8.5-44.el7                                                                                                                                                      Complete!

命令如下:

yum -y install gcc

yum -y install gcc-c++

安装需要软件包

安装docker镜像仓库命令如下:

sudo yum install -y yum-utils

yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

结果:

[root@192 ~]# yum install -y yum-utils
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile* base: mirrors.163.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com
Package yum-utils-1.1.31-54.el7_8.noarch already installed and latest version
Nothing to do
[root@192 ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror, langpacks
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

更新yum软件包索引

yum makecache fast

结果:

[root@192 ~]# yum makecache fast
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile* base: mirrors.163.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com
base                                                                                                                                                                  | 3.6 kB  00:00:00     
docker-ce-stable                                                                                                                                                      | 3.5 kB  00:00:00     
extras                                                                                                                                                                | 2.9 kB  00:00:00     
updates                                                                                                                                                               | 2.9 kB  00:00:00     
(1/2): docker-ce-stable/7/x86_64/updateinfo                                                                                                                           |   55 B  00:00:00     
(2/2): docker-ce-stable/7/x86_64/primary_db                                                                                                                           | 102 kB  00:00:00     
Metadata Cache Created

安装docker engine

yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

执行结果:

[root@192 ~]# yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile* base: mirrors.163.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package containerd.io.x86_64 0:1.6.20-3.1.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: containerd.io-1.6.20-3.1.el7.x86_64
---> Package docker-buildx-plugin.x86_64 0:0.10.4-1.el7 will be installed
---> Package docker-ce.x86_64 3:23.0.3-1.el7 will be installed
--> Processing Dependency: docker-ce-rootless-extras for package: 3:docker-ce-23.0.3-1.el7.x86_64
---> Package docker-ce-cli.x86_64 1:23.0.3-1.el7 will be installed
---> Package docker-compose-plugin.x86_64 0:2.17.2-1.el7 will be installed
--> Running transaction check
---> Package container-selinux.noarch 2:2.119.2-1.911c772.el7_8 will be installed
---> Package docker-ce-rootless-extras.x86_64 0:23.0.3-1.el7 will be installed
--> Processing Dependency: fuse-overlayfs >= 0.7 for package: docker-ce-rootless-extras-23.0.3-1.el7.x86_64
--> Processing Dependency: slirp4netns >= 0.4 for package: docker-ce-rootless-extras-23.0.3-1.el7.x86_64
--> Running transaction check
---> Package fuse-overlayfs.x86_64 0:0.7.2-6.el7_8 will be installed
--> Processing Dependency: libfuse3.so.3(FUSE_3.2)(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
--> Processing Dependency: libfuse3.so.3(FUSE_3.0)(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
--> Processing Dependency: libfuse3.so.3()(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
---> Package slirp4netns.x86_64 0:0.4.3-4.el7_8 will be installed
--> Running transaction check
---> Package fuse3-libs.x86_64 0:3.6.1-4.el7 will be installed
--> Finished Dependency ResolutionDependencies Resolved=============================================================================================================================================================================================Package                                             Arch                             Version                                               Repository                                  Size
=============================================================================================================================================================================================
Installing:containerd.io                                       x86_64                           1.6.20-3.1.el7                                        docker-ce-stable                            34 Mdocker-buildx-plugin                                x86_64                           0.10.4-1.el7                                          docker-ce-stable                            12 Mdocker-ce                                           x86_64                           3:23.0.3-1.el7                                        docker-ce-stable                            23 Mdocker-ce-cli                                       x86_64                           1:23.0.3-1.el7                                        docker-ce-stable                            13 Mdocker-compose-plugin                               x86_64                           2.17.2-1.el7                                          docker-ce-stable                            12 M
Installing for dependencies:container-selinux                                   noarch                           2:2.119.2-1.911c772.el7_8                             extras                                      40 kdocker-ce-rootless-extras                           x86_64                           23.0.3-1.el7                                          docker-ce-stable                           8.8 Mfuse-overlayfs                                      x86_64                           0.7.2-6.el7_8                                         extras                                      54 kfuse3-libs                                          x86_64                           3.6.1-4.el7                                           extras                                      82 kslirp4netns                                         x86_64                           0.4.3-4.el7_8                                         extras                                      81 kTransaction Summary
=============================================================================================================================================================================================
Install  5 Packages (+5 Dependent packages)Total download size: 103 M
Installed size: 366 M
Is this ok [y/d/N]: y
Downloading packages:
(1/10): container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm                                                                                                          |  40 kB  00:00:00     
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-buildx-plugin-0.10.4-1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY9 MB/s |  23 MB  00:00:42 ETA 
Public key for docker-buildx-plugin-0.10.4-1.el7.x86_64.rpm is not installed
(2/10): docker-buildx-plugin-0.10.4-1.el7.x86_64.rpm                                                                                                                  |  12 MB  00:00:11     
(3/10): containerd.io-1.6.20-3.1.el7.x86_64.rpm                                                                                                                       |  34 MB  00:00:32     
(4/10): docker-ce-23.0.3-1.el7.x86_64.rpm                                                                                                                             |  23 MB  00:00:22     
(5/10): docker-ce-rootless-extras-23.0.3-1.el7.x86_64.rpm                                                                                                             | 8.8 MB  00:00:08     
(6/10): fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm                                                                                                                       |  54 kB  00:00:00     
(7/10): slirp4netns-0.4.3-4.el7_8.x86_64.rpm                                                                                                                          |  81 kB  00:00:00     
(8/10): fuse3-libs-3.6.1-4.el7.x86_64.rpm                                                                                                                             |  82 kB  00:00:00     
(9/10): docker-ce-cli-23.0.3-1.el7.x86_64.rpm                                                                                                                         |  13 MB  00:00:12     
(10/10): docker-compose-plugin-2.17.2-1.el7.x86_64.rpm                                                                                                                |  12 MB  00:00:09     
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                        2.0 MB/s | 103 MB  00:00:51     
Retrieving key from https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
Importing GPG key 0x621E9F35:Userid     : "Docker Release (CE rpm) <docker@docker.com>"Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35From       : https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transactionInstalling : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch                                                                                                                       1/10 Installing : containerd.io-1.6.20-3.1.el7.x86_64                                                                                                                                      2/10 Installing : docker-compose-plugin-2.17.2-1.el7.x86_64                                                                                                                                3/10 Installing : slirp4netns-0.4.3-4.el7_8.x86_64                                                                                                                                         4/10 Installing : docker-buildx-plugin-0.10.4-1.el7.x86_64                                                                                                                                 5/10 Installing : 1:docker-ce-cli-23.0.3-1.el7.x86_64                                                                                                                                      6/10 Installing : fuse3-libs-3.6.1-4.el7.x86_64                                                                                                                                            7/10 Installing : fuse-overlayfs-0.7.2-6.el7_8.x86_64                                                                                                                                      8/10 Installing : 3:docker-ce-23.0.3-1.el7.x86_64                                                                                                                                          9/10 Installing : docker-ce-rootless-extras-23.0.3-1.el7.x86_64                                                                                                                           10/10 Verifying  : docker-ce-rootless-extras-23.0.3-1.el7.x86_64                                                                                                                            1/10 Verifying  : fuse3-libs-3.6.1-4.el7.x86_64                                                                                                                                            2/10 Verifying  : 1:docker-ce-cli-23.0.3-1.el7.x86_64                                                                                                                                      3/10 Verifying  : fuse-overlayfs-0.7.2-6.el7_8.x86_64                                                                                                                                      4/10 Verifying  : docker-buildx-plugin-0.10.4-1.el7.x86_64                                                                                                                                 5/10 Verifying  : 3:docker-ce-23.0.3-1.el7.x86_64                                                                                                                                          6/10 Verifying  : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch                                                                                                                       7/10 Verifying  : containerd.io-1.6.20-3.1.el7.x86_64                                                                                                                                      8/10 Verifying  : slirp4netns-0.4.3-4.el7_8.x86_64                                                                                                                                         9/10 Verifying  : docker-compose-plugin-2.17.2-1.el7.x86_64                                                                                                                               10/10 Installed:containerd.io.x86_64 0:1.6.20-3.1.el7               docker-buildx-plugin.x86_64 0:0.10.4-1.el7         docker-ce.x86_64 3:23.0.3-1.el7         docker-ce-cli.x86_64 1:23.0.3-1.el7        docker-compose-plugin.x86_64 0:2.17.2-1.el7        Dependency Installed:container-selinux.noarch 2:2.119.2-1.911c772.el7_8     docker-ce-rootless-extras.x86_64 0:23.0.3-1.el7     fuse-overlayfs.x86_64 0:0.7.2-6.el7_8     fuse3-libs.x86_64 0:3.6.1-4.el7    slirp4netns.x86_64 0:0.4.3-4.el7_8                    Complete!

启动docker

systemctl start docker
systemctl status docker

执行结果:

[root@192 ~]# systemctl status docker
● docker.service - Docker Application Container EngineLoaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)Active: inactive (dead)Docs: https://docs.docker.com
[root@192 ~]# systemctl start docker
[root@192 ~]# systemctl status docker
● docker.service - Docker Application Container EngineLoaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)Active: active (running) since Wed 2023-04-05 02:21:22 PDT; 2s agoDocs: https://docs.docker.comMain PID: 52695 (dockerd)Tasks: 7Memory: 84.4MCGroup: /system.slice/docker.service└─52695 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sockApr 05 02:21:20 192.168.12.130 dockerd[52695]: time="2023-04-05T02:21:20.657396557-07:00" level=info msg="[core] [Channel #4] Channel Connectivity change to READY" module=grpc
Apr 05 02:21:20 192.168.12.130 dockerd[52695]: time="2023-04-05T02:21:20.703841658-07:00" level=info msg="Loading containers: start."
Apr 05 02:21:21 192.168.12.130 dockerd[52695]: time="2023-04-05T02:21:21.621857331-07:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/1... IP address"
Apr 05 02:21:21 192.168.12.130 dockerd[52695]: time="2023-04-05T02:21:21.850315156-07:00" level=info msg="Firewalld: interface docker0 already part of docker zone, returning"
Apr 05 02:21:21 192.168.12.130 dockerd[52695]: time="2023-04-05T02:21:21.941546288-07:00" level=info msg="Loading containers: done."
Apr 05 02:21:22 192.168.12.130 dockerd[52695]: time="2023-04-05T02:21:22.004945157-07:00" level=info msg="Docker daemon" commit=59118bf graphdriver=overlay2 version=23.0.3
Apr 05 02:21:22 192.168.12.130 dockerd[52695]: time="2023-04-05T02:21:22.005104385-07:00" level=info msg="Daemon has completed initialization"
Apr 05 02:21:22 192.168.12.130 systemd[1]: Started Docker Application Container Engine.
Apr 05 02:21:22 192.168.12.130 dockerd[52695]: time="2023-04-05T02:21:22.027054127-07:00" level=info msg="[core] [Server #7] Server created" module=grpc
Apr 05 02:21:22 192.168.12.130 dockerd[52695]: time="2023-04-05T02:21:22.055933730-07:00" level=info msg="API listen on /run/docker.sock"
Hint: Some lines were ellipsized, use -l to show in full.

hello-world

[root@192 ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f
Status: Downloaded newer image for hello-world:latestHello 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 theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.To try something more ambitious, you can run an Ubuntu container with:$ docker run -it ubuntu bashShare 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@192 ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    feb5d9fea6a5   18 months ago   13.3kB

问题记录

现象:

[root@192 ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'.

message日志中的报错如下:

Apr  5 03:00:08 192 dockerd: time="2023-04-05T03:00:08.158673167-07:00" level=info msg="Attempting next endpoint for pull after error: Get \"https://pylcjgsv.mirror.aliyuncs.com/v2/\": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)"
Apr  5 03:00:23 192 dockerd: time="2023-04-05T03:00:23.159412732-07:00" level=warning msg="Error getting v2 registry: Get \"https://registry-1.docker.io/v2/\": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)"
Apr  5 03:00:23 192 dockerd: time="2023-04-05T03:00:23.159491469-07:00" level=error msg="Not continuing with pull after error: Get \"https://registry-1.docker.io/v2/\": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)"

尝试了很多方法都没有效果,后面是用修改dns解析的方法解决的.
修改如下:

[root@192 etc]# cat resolv.conf 
# Generated by NetworkManager
search localdomain
nameserver 192.168.12.2
nameserver 8.8.8.8 #添加了这一条dns

目前没有弄清楚为什么这样就可以了,下面是参考的博客:

https://cloud.tencent.com/developer/article/1627708
https://blog.csdn.net/qq_36963950/article/details/127523445

http://www.ppmy.cn/news/39326.html

相关文章

vue下载文件

注意请求时加入&#xff1a;responseType: bloburl&#xff1a;写全了&#xff0c;因为前后端端口号不同downloadImage(imgUrl) {let formData new FormData();formData.append(fileName, this.getFilename(imgUrl)); // 用于后端下载文件的路径axios.post(http://localhost:8…

DehazeNet: An End-to-End System for Single ImageHaze Removal

Abstract 单图像雾霾去除是一个具有挑战性的不适定问题。现有的方法使用各种约束/先验来获得似是而非的去雾解。实现雾霾去除的关键是对输入的雾霾图像进行介质透射图的估计。在本文中&#xff0c;我们提出了一个可训练的端到端系统称为DehazeNet&#xff0c;用于介质传输估计…

美摄汽车数据匿名化方案:精准、高效、低耗

近年来随着智能网联汽车的升级迭代&#xff0c;车辆采集数据的量级与敏感度也日渐提升。以车载摄像头为例&#xff0c;当前智能汽车车身配备的摄像头数量逐渐增加&#xff0c;采集到的信息也更加复杂多样。根据来源主体不同&#xff0c;车联网敏感数据大致可以划分为以下几类&a…

rk3568 Android audio 调试

rk3568 Android tiny-alsa工具 Android 平台使用audio HAL应该是Linux alsa-utils 的变种&#xff1b;相对后者前者更简单&#xff0c;但是功能基本相同&#xff1b; 在使用命令遍历声卡和设备时&#xff0c;同样支持按照序号和名字索引&#xff0c;这点比较赞。录音或者播放测…

leetcode:验证回文串(详解)

前言&#xff1a;内容包括&#xff1a;题目&#xff0c;代码实现&#xff0c;大致思路 题目&#xff1a; 如果在将所有大写字符转换为小写字符、并移除所有非字母数字字符之后&#xff0c;短语正着读和反着读都一样。则可以认为该短语是一个 回文串 。 字母和数字都属于字母…

PX4从放弃到精通(二十七):固定翼姿态控制

文章目录前言一、roll/pitch姿态/角速率控制二、偏航角速率控制三、主程序前言 固件版本 PX4 1.13.2 欢迎交流学习&#xff0c;可加左侧名片 一、roll/pitch姿态/角速率控制 roll/pitch的姿态控制类似&#xff0c;这里只介绍roll姿态控制&#xff0c; 代码位置&#xff1a; …

left join 中 的on的使用和on后加where 和 and 的区别

一、left join on on条件是在生成临时表时使用的条件&#xff0c;它不管on中的条件是否为真&#xff0c;都会返回左边表中的记录。 注意&#xff1a;on 后面跟的是关联表的查询条件 二、left join on and &#xff08;1&#xff09;如果and语句是对左表进行过滤的&#xff0c;…

Pandas玩转文本处理

数据处理&#xff0c;也是风控非常重要的一个环节&#xff0c;甚至说是模型成败的关键环节。因此&#xff0c;娴熟简洁的数据处理技巧&#xff0c;是提高建模效率和建模质量的必要能力。 向量化操作的概述 对于文本数据的处理(清洗)&#xff0c;是现实工作中的数据时不可或缺的…