Ubuntu20.04 解决Docker连接超时+拉取镜像超时+VScode docker开发准备
创始人
2024-11-10 02:40:36
0

一、安装Docker

1. 卸载老版本

sudo apt-get remove docker docker-engine docker.io containerd runc 

2. 安装必要依赖

sudo apt-get update sudo apt-get install -y \     apt-transport-https \     ca-certificates \     curl \     gnupg-agent 

3. 设置软件源

注意:这里博主使用ubuntu系统中默认的tinghua源或aliyun源会出现如下连接问题。

Err:7 https://download.docker.com/linux/ubuntu focal InRelease Could not connect to download.docker.com:443 (2a03:2880:f129:83:face:b00c:0:25de), connection timed out Could not connect to download.docker.com:443 (179.60.193.16), connection timed out Fetched 2,910 B in 36s (81 B/s) W: Failed to fetch https://download.docker.com/linux/ubuntu/dists/focal/InRelease Could not connect to download.docker.com:443 (2a03:2880:f129:83:face:b00c:0:25de), connection timed out Could not connect to download.docker.com:443 (179.60.193.16), connection timed out 

看到网上说的原因有很多种可能,可能是代理问题,也可能是防火墙问题,这里我们直接手动换成阿里源的docker软件列表

1. 首先设置密钥 # 官方密钥(不建议) curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg  # 阿里密钥(推荐) curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg 2. 设置软件源 # 官方源(不建议用) echo \ "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null  # 阿里源(推荐) 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 

4.更新软件列表

sudo apt-get update 

得到反馈:

sudo apt-get update  命中:1 http://mirrors.aliyun.com/ubuntu focal InRelease 命中:2 http://mirrors.aliyun.com/ubuntu focal-updates InRelease                 命中:3 https://mirrors.aliyun.com/docker-ce/linux/ubuntu focal InRelease        命中:4 http://mirrors.aliyun.com/ubuntu focal-backports InRelease               命中:5 http://security.ubuntu.com/ubuntu focal-security InRelease               正在读取软件包列表... 完成 

软件列表更新完成

5. 安装Docker

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin 

等待安装成功…(如果还是连接失败,那真就是网络问题了,注意检查互联网连接!!)

6. 安装验证

sudo docker run hello-world 

对于首次安装docker的用户来说,会在docker网站上pull下来一个新的image,叫hello-world。但是这里博主依然出现了连接问题,就是一直pull不下来。

为此,博主使用了鱼香ROS里的docker镜像代理,实测非常好用,几乎是傻瓜式,以下内容均为引用。

(1)首先,通过以下命令下载并运行一键安装工具:

wget http://fishros.com/install -O fishros && bash fishros  

(2)运行后,您将看到如下界面:

基础检查通过... =============================================================================== ======欢迎使用一键安装工具,人生苦短,三省吾身,省时省力省心!======= ======一键安装已开源,请放心使用:https://github.com/fishros/install ======= ===============================================================================      ... (界面省略)  请输入[]内的数字以选择: 17 

选择数字 17,进入Docker代理配置。

(3)进入Docker代理配置界面,选择 2

请选择代理模式,如果不清楚可以选2 [1]:科学上网模式(需要本地有支持HTTP代理) [2]:服务模式(需要提供支持Docker代理的服务器地址) [3]:删除所有模式代理 [0]:quit 请输入[]内的数字以选择:2 

(4)接下来选择代理加速网址,选择1

RUN Choose Task:[请输入括号内的数字] 请选择代理加速网址 [1]:https://dockerpull.com [2]:https://docker.fxxk.dedyn.io [3]:https://ac77d18f43e44819b553040f294b8f9b.mirror.swr.myhuaweicloud.com [0]:quit 请输入[]内的数字以选择:1 

系统会自动创建并写入代理配置文件,并重启Docker服务:

创建文件:/etc/docker/daemon.json 在/etc/docker//daemon.json写入了{"registry-mirrors": ["https://dockerpull.com"]},接下来为你重启Docker! Run CMD Task:[sudo systemctl daemon-reload] [-]Result:success                            Run CMD Task:[sudo systemctl restart docker] [-]Result:success                            

(5)配置完成后,您可以尝试再次拉取镜像:

docker pull hello-world  --- hello-world: Pulling from library/ubuntu 9ea8908f4765: Already exists  Digest: sha256:0b897358ff6624825fb50d20ffb605ab0eaea77ced0adb8c6a4b756513dec6fc Status: Downloaded newer image for hello-world 

(6)运行hello-world镜像

sudo docker run hello-world  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/  

docker安装完成!

二、使用VScode进行docker开发

1. 安装插件

在Vscode中安装如下两个插件:
在这里插入图片描述

安装完成后,左侧工具栏会出现这个图标在这里插入图片描述

但是进入docker后发现,存在这样一个错误:
在这里插入图片描述

2. 修改docker服务权限

第一步:创建组

sudo groupadd docker 

第二步: 添加到用户组

sudo usermod -aG docker ${USER} 

第三步: 文件赋权限

sudo chmod 666 /var/run/docker.sock 

第四步:重启docker服务

 sudo systemctl restart docker 

重启Vscode,大功告成!
在这里插入图片描述

参考链接

https://docs.docker.com/engine/install/ubuntu/

https://www.huixinglaile.com/archives/117a5c58.html

https://medium.com/@praveenadoni4456/error-got-permission-denied-while-trying-to-connect-to-the-docker-daemon-socket-at-e68bfab8146a

https://mp.weixin.qq.com/s/Vs8mgwCj0zapKndiT3C3_Q

相关内容

热门资讯

秒懂普及”珊瑚互娱房卡领取码“... 秒懂普及”珊瑚互娱房卡领取码“王者大厅房间卡怎么购买游戏中心打开微信,添加客服【113857776】...
秒懂教程!我买微信牛牛房卡链接... 斗牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:71319951许多玩家在游戏中会购买房卡来享受...
正规平台有哪些,怎么买斗牛房卡... 微信游戏中心:火神大厅房卡在哪里买打开微信,添加客服微信【88355042】,进入游戏中心或相关小程...
给大家讲解“购买斗牛房卡联系方... 起点大厅是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:160470940许多玩家在游戏中会购买房卡...
ia攻略/游戏推荐斗牛房卡出售... ia攻略/游戏推荐斗牛房卡出售长虹大厅/科技房卡多少钱一张Sa9Ix苹果iPhone 17手机即将进...
一分钟实测分享”时光互娱低价获... 第二也可以在游戏内商城:在游戏界面中找到 “微信金花,斗牛链接房卡”“商城”选项,选择房卡的购买选项...
一分钟了解!牛牛房卡游戏平台加... 微信游戏中心:乐乐堂房卡在哪里买打开微信,添加客服微信【88355042】,进入游戏中心或相关小程序...
正规平台有哪些,金花房卡是正规... 海航大厅是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:【3329006910】或QQ:332900...
秒懂教程!微信牛牛房间怎么弄,... 斗牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:66336574许多玩家在游戏中会购买房卡来享受...
终于找到“微信怎样开炸金花房间... 金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:160470940许多玩家在游戏中会购买房卡来享...
秒懂百科”海洋世界哪里有详细房... 哪里有详细房卡介绍是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:113857776许多玩家在游戏中...
头条推荐!游戏推荐斗牛房卡出售... 头条推荐!游戏推荐斗牛房卡出售新神兽/流樱大厅/微信链接房间卡怎么购买新神兽/流樱大厅是一款非常受欢...
推荐一款!怎么买斗牛房卡朱雀大... 微信游戏中心:朱雀大厅房卡在哪里买打开微信,添加客服微信【88355042】,进入游戏中心或相关小程...
玩家攻略,牛牛房卡代理荣耀联盟... 荣耀联盟是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:【3329006910】或QQ:332900...
IA解析/牛牛房卡游戏平台加盟... IA解析/牛牛房卡游戏平台加盟天道联盟/随意玩/微信链接房卡卖家联系方式Sa9Ix苹果iPhone ...
分享经验”百万牛哪里买低价获取... 分享经验”百万牛哪里买低价获取“新老夫子房卡充值游戏中心打开微信,添加客服【113857776】,进...
一分钟了解!金花房卡出售大众互... 今 日消息,大众互娱房卡添加微信33549083 苹果今日发布了 iOS 16.1 正式版更新,简单...
秒懂教程!微信买链接拼三张房卡... 拼三张是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:56001354许多玩家在游戏中会购买房卡来享...
房卡必备教程“购买金花房卡联系... 新琉璃金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:44346008许多玩家在游戏中会购买房卡...
1分秒分析”茄子娱乐房卡详细充... 第二也可以在游戏内商城:在游戏界面中找到 “微信金花,斗牛链接房卡”“商城”选项,选择房卡的购买选项...