Ubuntu20.04 解决Docker连接超时+拉取镜像超时+VScode docker开发准备 ...

打印 上一主题 下一主题

主题 574|帖子 574|积分 1722

一、安装Docker

1. 卸载老版本

  1. sudo apt-get remove docker docker-engine docker.io containerd runc
复制代码
2. 安装必要依赖

  1. sudo apt-get update
  2. sudo apt-get install -y \
  3.     apt-transport-https \
  4.     ca-certificates \
  5.     curl \
  6.     gnupg-agent
复制代码
3. 设置软件源

注意:这里博主使用ubuntu系统中默认的tinghua源或aliyun源会出现如下连接问题。
  1. Err:7 https://download.docker.com/linux/ubuntu focal InRelease
  2. 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
  3. Fetched 2,910 B in 36s (81 B/s)
  4. 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. 1. 首先设置密钥
  2. # 官方密钥(不建议)
  3. curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  4. # 阿里密钥(推荐)
  5. curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  6. 2. 设置软件源
  7. # 官方源(不建议用)
  8. echo \
  9. "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  10. $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  11. # 阿里源(推荐)
  12. echo \
  13. "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
  14. $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
复制代码
4.更新软件列表

  1. sudo apt-get update
复制代码
得到反馈:
  1. sudo apt-get update
  2. 命中: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

  1. sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
复制代码
等待安装成功…(如果还是连接失败,那真就是网络问题了,注意查抄互联网连接!!)
6. 安装验证

  1. sudo docker run hello-world
复制代码
对于初次安装docker的用户来说,会在docker网站上pull下来一个新的image,叫hello-world。但是这里博主依然出现了连接问题,就是一直pull不下来。
为此,博主使用了鱼香ROS里的docker镜像署理,实测非常好用,几乎是傻瓜式,以下内容均为引用。
(1)首先,通过以下命令下载并运行一键安装工具:
  1. wget http://fishros.com/install -O fishros && bash fishros
复制代码
(2)运行后,您将看到如下界面:
  1. 基础检查通过...
  2. ===============================================================================
  3. ======欢迎使用一键安装工具,人生苦短,三省吾身,省时省力省心!=======
  4. ======一键安装已开源,请放心使用:https://github.com/fishros/install =======
  5. ===============================================================================
  6.     ... (界面省略)
  7. 请输入[]内的数字以选择: 17
复制代码
选择数字 17,进入Docker署理配置。
(3)进入Docker署理配置界面,选择 2:
  1. 请选择代理模式,如果不清楚可以选2
  2. [1]:科学上网模式(需要本地有支持HTTP代理)
  3. [2]:服务模式(需要提供支持Docker代理的服务器地址)
  4. [3]:删除所有模式代理
  5. [0]:quit
  6. 请输入[]内的数字以选择:2
复制代码
(4)接下来选择署理加速网址,选择1:
  1. RUN Choose Task:[请输入括号内的数字]
  2. 请选择代理加速网址
  3. [1]:https://dockerpull.com
  4. [2]:https://docker.fxxk.dedyn.io
  5. [3]:https://ac77d18f43e44819b553040f294b8f9b.mirror.swr.myhuaweicloud.com
  6. [0]:quit
  7. 请输入[]内的数字以选择:1
复制代码
系统会自动创建并写入署理配置文件,并重启Docker服务:
  1. 创建文件:/etc/docker/daemon.json
  2. 在/etc/docker//daemon.json写入了{"registry-mirrors": ["https://dockerpull.com"]},接下来为你重启Docker!
  3. Run CMD Task:[sudo systemctl daemon-reload]
  4. [-]Result:success                           
  5. Run CMD Task:[sudo systemctl restart docker]
  6. [-]Result:success                           
复制代码
(5)配置完成后,您可以尝试再次拉取镜像:
  1. docker pull hello-world
  2. ---
  3. hello-world: Pulling from library/ubuntu
  4. 9ea8908f4765: Already exists
  5. Digest: sha256:0b897358ff6624825fb50d20ffb605ab0eaea77ced0adb8c6a4b756513dec6fc
  6. Status: Downloaded newer image for hello-world
复制代码
(6)运行hello-world镜像
  1. sudo docker run hello-world
  2. 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 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/
复制代码
docker安装完成!
二、使用VScode举行docker开发

1. 安装插件

在Vscode中安装如下两个插件:

安装完成后,左侧工具栏会出现这个图标

但是进入docker后发现,存在如许一个错误:

2. 修改docker服务权限

第一步:创建组
  1. sudo groupadd docker
复制代码
第二步: 添加到用户组
  1. sudo usermod -aG docker ${USER}
复制代码
第三步: 文件赋权限
  1. sudo chmod 666 /var/run/docker.sock
复制代码
第四步:重启docker服务
  1. sudo systemctl restart docker
复制代码
重启Vscode,大功告成!

参考链接

https://docs.docker.com/engine/install/ubuntu/#firewall-limitations
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

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

莱莱

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表