【第四节】ubuntu server安装docker

首先更新软件源

bash 复制代码
sudo apt update
sudo apt upgrade

安装docker

下载 Docker 官方 GPG 密钥

bash 复制代码
# 1. 下载 Docker 官方 GPG 密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

再次更新软件源

bash 复制代码
# 再次更新软件源
sudo apt update

安装docker

bash 复制代码
# 安装docker
sudo apt install docker-ce

安装后输出如下信息,https握手失败

bash 复制代码
root@server001:/home/zxd# sudo apt install docker-ce
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  containerd.io docker-buildx-plugin docker-ce-cli docker-ce-rootless-extras docker-compose-plugin libslirp0 pigz slirp4netns
Suggested packages:
  cgroupfs-mount | cgroup-lite docker-model-plugin
The following NEW packages will be installed:
  containerd.io docker-buildx-plugin docker-ce docker-ce-cli docker-ce-rootless-extras docker-compose-plugin libslirp0 pigz slirp4netns
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 103 MB of archives.
After this operation, 429 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Ign:4 https://download.docker.com/linux/ubuntu jammy/stable amd64 containerd.io amd64 1.7.27-1
Ign:5 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce-cli amd64 5:28.3.2-1~ubuntu.22.04~jammy
Get:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 pigz amd64 2.6-1 [63.6 kB]
Ign:6 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce amd64 5:28.3.2-1~ubuntu.22.04~jammy
Get:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/main amd64 libslirp0 amd64 4.6.1-1build1 [61.5 kB]
Get:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 slirp4netns amd64 1.0.1-2 [28.2 kB]
Ign:7 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-buildx-plugin amd64 0.25.0-1~ubuntu.22.04~jammy
Ign:8 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce-rootless-extras amd64 5:28.3.2-1~ubuntu.22.04~jammy
Ign:9 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-compose-plugin amd64 2.38.2-1~ubuntu.22.04~jammy
Ign:4 https://download.docker.com/linux/ubuntu jammy/stable amd64 containerd.io amd64 1.7.27-1
Ign:5 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce-cli amd64 5:28.3.2-1~ubuntu.22.04~jammy
Ign:6 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce amd64 5:28.3.2-1~ubuntu.22.04~jammy
Ign:7 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-buildx-plugin amd64 0.25.0-1~ubuntu.22.04~jammy
Ign:8 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce-rootless-extras amd64 5:28.3.2-1~ubuntu.22.04~jammy
Ign:9 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-compose-plugin amd64 2.38.2-1~ubuntu.22.04~jammy
Ign:4 https://download.docker.com/linux/ubuntu jammy/stable amd64 containerd.io amd64 1.7.27-1
Ign:5 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce-cli amd64 5:28.3.2-1~ubuntu.22.04~jammy
Ign:6 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce amd64 5:28.3.2-1~ubuntu.22.04~jammy
Ign:7 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-buildx-plugin amd64 0.25.0-1~ubuntu.22.04~jammy
Ign:8 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce-rootless-extras amd64 5:28.3.2-1~ubuntu.22.04~jammy
Ign:9 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-compose-plugin amd64 2.38.2-1~ubuntu.22.04~jammy
Err:4 https://download.docker.com/linux/ubuntu jammy/stable amd64 containerd.io amd64 1.7.27-1                                                                                                                                                                            
  Could not handshake: Error in the pull function. [IP: 18.65.229.113 443]
Err:5 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce-cli amd64 5:28.3.2-1~ubuntu.22.04~jammy                                                                                                                                                       
  Could not handshake: Error in the pull function. [IP: 18.65.229.113 443]
Err:6 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce amd64 5:28.3.2-1~ubuntu.22.04~jammy                                                                                                                                                           
  Could not handshake: Error in the pull function. [IP: 18.65.229.113 443]
Err:7 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-buildx-plugin amd64 0.25.0-1~ubuntu.22.04~jammy                                                                                                                                                  
  Could not handshake: Error in the pull function. [IP: 18.65.229.113 443]
Err:8 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce-rootless-extras amd64 5:28.3.2-1~ubuntu.22.04~jammy                                                                                                                                           
  Could not handshake: Error in the pull function. [IP: 18.65.229.113 443]
Err:9 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-compose-plugin amd64 2.38.2-1~ubuntu.22.04~jammy                                                                                                                                                 
  Could not handshake: Error in the pull function. [IP: 18.65.229.113 443]
Fetched 153 kB in 8s (18.5 kB/s)                                                                                                                                                                                                                                          
E: Failed to fetch https://download.docker.com/linux/ubuntu/dists/jammy/pool/stable/amd64/containerd.io_1.7.27-1_amd64.deb  Could not handshake: Error in the pull function. [IP: 18.65.229.113 443]
E: Failed to fetch https://download.docker.com/linux/ubuntu/dists/jammy/pool/stable/amd64/docker-ce-cli_28.3.2-1%7eubuntu.22.04%7ejammy_amd64.deb  Could not handshake: Error in the pull function. [IP: 18.65.229.113 443]
E: Failed to fetch https://download.docker.com/linux/ubuntu/dists/jammy/pool/stable/amd64/docker-ce_28.3.2-1%7eubuntu.22.04%7ejammy_amd64.deb  Could not handshake: Error in the pull function. [IP: 18.65.229.113 443]
E: Failed to fetch https://download.docker.com/linux/ubuntu/dists/jammy/pool/stable/amd64/docker-buildx-plugin_0.25.0-1%7eubuntu.22.04%7ejammy_amd64.deb  Could not handshake: Error in the pull function. [IP: 18.65.229.113 443]
E: Failed to fetch https://download.docker.com/linux/ubuntu/dists/jammy/pool/stable/amd64/docker-ce-rootless-extras_28.3.2-1%7eubuntu.22.04%7ejammy_amd64.deb  Could not handshake: Error in the pull function. [IP: 18.65.229.113 443]
E: Failed to fetch https://download.docker.com/linux/ubuntu/dists/jammy/pool/stable/amd64/docker-compose-plugin_2.38.2-1%7eubuntu.22.04%7ejammy_amd64.deb  Could not handshake: Error in the pull function. [IP: 18.65.229.113 443]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

更换国内源重新安装

移除原有docker源

bash 复制代码
#移除原有docker源
root@server001:/etc/apt/sources.list.d# rm docker.list
root@server001:/etc/apt/sources.list.d# 

下载阿里云的 Docker GPG 密钥

bash 复制代码
# 下载阿里云的 Docker GPG 密钥
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

添加阿里云 Docker APT 源

bash 复制代码
# 添加阿里云 Docker APT 源
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

更新软件源

bash 复制代码
#更新软件源
sudo apt update

安装docker

bash 复制代码
#安装docker
sudo apt install docker-ce

输出证明安装成功

bash 复制代码
root@server001:/etc/apt/sources.list.d# sudo apt install docker-ce
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  containerd.io docker-buildx-plugin docker-ce-cli docker-ce-rootless-extras docker-compose-plugin libslirp0 pigz slirp4netns
Suggested packages:
  cgroupfs-mount | cgroup-lite docker-model-plugin
The following NEW packages will be installed:
  containerd.io docker-buildx-plugin docker-ce docker-ce-cli docker-ce-rootless-extras docker-compose-plugin libslirp0 pigz slirp4netns
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 103 MB/103 MB of archives.
After this operation, 429 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 https://mirrors.aliyun.com/docker-ce/linux/ubuntu jammy/stable amd64 containerd.io amd64 1.7.27-1 [30.5 MB]
Get:2 https://mirrors.aliyun.com/docker-ce/linux/ubuntu jammy/stable amd64 docker-ce-cli amd64 5:28.3.2-1~ubuntu.22.04~jammy [16.5 MB]
Get:3 https://mirrors.aliyun.com/docker-ce/linux/ubuntu jammy/stable amd64 docker-ce amd64 5:28.3.2-1~ubuntu.22.04~jammy [19.7 MB]
Get:4 https://mirrors.aliyun.com/docker-ce/linux/ubuntu jammy/stable amd64 docker-buildx-plugin amd64 0.25.0-1~ubuntu.22.04~jammy [15.6 MB]
Get:5 https://mirrors.aliyun.com/docker-ce/linux/ubuntu jammy/stable amd64 docker-ce-rootless-extras amd64 5:28.3.2-1~ubuntu.22.04~jammy [6,481 kB]                                                                                                                       
Get:6 https://mirrors.aliyun.com/docker-ce/linux/ubuntu jammy/stable amd64 docker-compose-plugin amd64 2.38.2-1~ubuntu.22.04~jammy [14.2 MB]                                                                                                                              
Fetched 103 MB in 9s (11.7 MB/s)                                                                                                                                                                                                                                          
Selecting previously unselected package containerd.io.
(Reading database ... 74997 files and directories currently installed.)
Preparing to unpack .../0-containerd.io_1.7.27-1_amd64.deb ...
Unpacking containerd.io (1.7.27-1) ...
Selecting previously unselected package docker-ce-cli.
Preparing to unpack .../1-docker-ce-cli_5%3a28.3.2-1~ubuntu.22.04~jammy_amd64.deb ...
Unpacking docker-ce-cli (5:28.3.2-1~ubuntu.22.04~jammy) ...
Selecting previously unselected package docker-ce.
Preparing to unpack .../2-docker-ce_5%3a28.3.2-1~ubuntu.22.04~jammy_amd64.deb ...
Unpacking docker-ce (5:28.3.2-1~ubuntu.22.04~jammy) ...
Selecting previously unselected package pigz.
Preparing to unpack .../3-pigz_2.6-1_amd64.deb ...
Unpacking pigz (2.6-1) ...
Selecting previously unselected package docker-buildx-plugin.
Preparing to unpack .../4-docker-buildx-plugin_0.25.0-1~ubuntu.22.04~jammy_amd64.deb ...
Unpacking docker-buildx-plugin (0.25.0-1~ubuntu.22.04~jammy) ...
Selecting previously unselected package docker-ce-rootless-extras.
Preparing to unpack .../5-docker-ce-rootless-extras_5%3a28.3.2-1~ubuntu.22.04~jammy_amd64.deb ...
Unpacking docker-ce-rootless-extras (5:28.3.2-1~ubuntu.22.04~jammy) ...
Selecting previously unselected package docker-compose-plugin.
Preparing to unpack .../6-docker-compose-plugin_2.38.2-1~ubuntu.22.04~jammy_amd64.deb ...
Unpacking docker-compose-plugin (2.38.2-1~ubuntu.22.04~jammy) ...
Selecting previously unselected package libslirp0:amd64.
Preparing to unpack .../7-libslirp0_4.6.1-1build1_amd64.deb ...
Unpacking libslirp0:amd64 (4.6.1-1build1) ...
Selecting previously unselected package slirp4netns.
Preparing to unpack .../8-slirp4netns_1.0.1-2_amd64.deb ...
Unpacking slirp4netns (1.0.1-2) ...
Setting up docker-buildx-plugin (0.25.0-1~ubuntu.22.04~jammy) ...
Setting up containerd.io (1.7.27-1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.service.
Setting up docker-compose-plugin (2.38.2-1~ubuntu.22.04~jammy) ...
Setting up docker-ce-cli (5:28.3.2-1~ubuntu.22.04~jammy) ...
Setting up libslirp0:amd64 (4.6.1-1build1) ...
Setting up pigz (2.6-1) ...
Setting up docker-ce-rootless-extras (5:28.3.2-1~ubuntu.22.04~jammy) ...
Setting up slirp4netns (1.0.1-2) ...
Setting up docker-ce (5:28.3.2-1~ubuntu.22.04~jammy) ...
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.10) ...
Scanning processes...                                                                                                                                                                                                                                                      
Scanning linux images...                                                                                                                                                                                                                                                   

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.
root@server001:/etc/apt/sources.list.d# 

docker安装完成,尝试拉去hellow-world并运行,以测试docker是否功能正常

拉去hello world镜像,但是报错了网络问题

bash 复制代码
root@server001:/etc/apt/sources.list.d# docker pull hello-world
Using default tag: latest
Error response from daemon: Get "https://registry-1.docker.io/v2/": context deadline exceeded
root@server001:/etc/apt/sources.list.d# 

更换国内镜像源,但其实这条路已经被堵死了,因为不可言说的原因国内所有的仓库都已经下架了,你可能需要去想点其他办法来解决这个问题,我就不多说了,但这是个可以解决的问题,最后我是购买了docker加速器解决的问题,有人会说阿里云,腾讯云,什么的,请你去看看他们的公告,仅限自家云产品加速使用,那些免费的其他公共地址早在2024年就发过下架公告了。
拉取hello-world的信息这里就不截图,也不粘帖了,因为有隐私信息,反正问题最后是解决了,我们直接跳到运行hello-world这一步,可以已经运行了hello-world

写在最后,在我们从第一章在hyper-v里安装ubuntu server到今天安装完成docker,运行hello-world,镜像的问题是我遇到最大的挑战,当然也解决了它,但耗费的差不多三个小时

下一章我们将最原始的方式在docker里部署一个基于python flask的http接口,然后通过调试工具进行请求

相关推荐
cqsztech1 小时前
oracle linux 10 +pg18 源码安装要点
linux·数据库·oracle
奥尔特星云大使1 小时前
ALTER 与 UPDATE、DROP 与 DELETE区别
linux·运维·数据库·mysql
duangww2 小时前
部署sapui5应用到linux
linux·sap fiori
siriuuus2 小时前
Linux ssh/scp/sftp命令使用及免密登录配置
linux·ssh·sftp·scp
teacher伟大光荣且正确4 小时前
Linux 下编译openssl
linux·运维·服务器
dlz08364 小时前
--group-start/--group-end 能不能解决 OpenSSL 1.0 vs 1.1 的优先级问题?
linux·运维·服务器·软件需求
小池先生5 小时前
activemq延迟消息变成实时收到了?
linux·数据库·activemq
tryCbest6 小时前
Linux系统下安装使用Redis
linux·运维·redis
AuroBreeze7 小时前
xv6-2023 - primes Lab
linux·运维·服务器
DIY机器人工房7 小时前
NAT 模式、命令行版、桥接模式方式给ubuntu虚拟机配网步骤:
linux·网络协议·ubuntu·嵌入式·桥接模式·diy机器人工房