Ubuntu Dockerfile执行apt-get update时出现403 Forbidden错误求助
问题:WSL2+Docker Desktop环境下Ubuntu 20.04镜像构建时apt-get update失败
我是Docker新手,当前在WSL2 Ubuntu 20.04与Docker Desktop环境中测试容器内ping google.com。构建Ubuntu:20.04镜像时,RUN apt-get update步骤失败,报错:E: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy/InRelease 403 Forbidden [IP: 91.189.91.39 80]
另外,构建Alpine:latest镜像执行RUN apk update正常,WSL2内直接执行apt-get update也没问题。
已尝试的解决方案
- 修改/etc/docker/daemon.json中的DNS配置
- 修改/etc/apt/source.lists中的协议(http改ftp/https)
- 安装apt-transport-https
- 更新适配本地区域的apt镜像源
- 将WSL2发行版升级至22.04 jammy
- 删除/var/lib/apt/lists/下所有文件后执行apt-get update
- 重新安装Docker Desktop
相关文件内容
Dockerfile
#pull base image FROM ubuntu:20.04 #sudo su USER root #update and clean packages RUN : \ && apt-get update \ && rm -rf /var/cache/apk/* \ && apt-get clean \ && : #copy all files in current directory into container directory /home/app COPY . /home/app #set /home/app as working directory WORKDIR /home/app #execute ping.sh ENTRYPOINT ["sh", "ping.sh"]
ping.sh
#!/bin/bash ping google.com
/etc/docker/daemon.json
{ "dns": ["192.168.224.1", "8.8.8.8"] }
/etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf: # [network] # generateResolvConf = false nameserver 172.30.176.1
构建错误日志
执行docker build -t test-ping-ubuntu:0.1 .后的错误输出:
[+] Building 52.1s (7/9) => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 442B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/library/ubuntu:20.04 45.6s => [auth] library/ubuntu:pull token for registry-1.docker.io 0.0s => [1/4] FROM docker.io/library/ubuntu:20.04@sha256:0e0402cd13f68137edb0266e1d2c682f217814420f 5.1s => => resolve docker.io/library/ubuntu:20.04@sha256:0e0402cd13f68137edb0266e1d2c682f217814420f 0.0s => => sha256:0e0402cd13f68137edb0266e1d2c682f217814420f2d43d300ed8f65479b14fb 1.42kB / 1.42kB 0.0s => => sha256:8eb87f3d6c9f2feee114ff0eff93ea9dfd20b294df0a0353bd6a4abf403336fe 529B / 529B 0.0s => => sha256:d5447fc01ae62c20beffbfa50bc51b2797f9d7ebae031b8c2245b5be8ff1c75b 1.46kB / 1.46kB 0.0s => => sha256:846c0b181fff0c667d9444f8378e8fcfa13116da8d308bf21673f7e4bea8d58 28.58MB / 28.58MB 4.0s => => extracting sha256:846c0b181fff0c667d9444f8378e8fcfa13116da8d308bf21673f7e4bea8d580 0.9s => [internal] load build context 0.0s => => transferring context: 500B 0.0s => ERROR [2/4] RUN : && apt-get update && rm -rf /var/cache/apk/* && apt-get clean 1.3s ------ > [2/4] RUN : && apt-get update && rm -rf /var/cache/apk/* && apt-get clean && :: #6 0.405 Err:1 http://security.ubuntu.com/ubuntu focal-security InRelease #6 0.405 403 Forbidden [IP: 185.125.190.39 80] #6 0.623 Err:2 http://archive.ubuntu.com/ubuntu focal InRelease #6 0.623 403 Forbidden [IP: 185.125.190.36 80] #6 0.631 Err:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease #6 0.631 403 Forbidden [IP: 185.125.190.36 80] #6 0.639 Err:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease #6 0.639 403 Forbidden [IP: 185.125.190.36 80] #6 0.642 Reading package lists... #6 0.648 E: The repository 'http://security.ubuntu.com/ubuntu focal-security InRelease' is not signed. #6 0.648 E: Failed to fetch http://security.ubuntu.com/ubuntu/dists/focal-security/InRelease 403 Forbidden [IP: 185.125.190.39 80] #6 0.648 E: The repository 'http://archive.ubuntu.com/ubuntu focal InRelease' is not signed. #6 0.648 E: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal/InRelease 403 Forbidden [IP: 185.125.190.36 80] #6 0.648 E: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal-updates/InRelease 403 Forbidden [IP: 185.125.190.36 80] #6 0.648 E: The repository 'http://archive.ubuntu.com/ubuntu focal-updates InRelease' is not signed. #6 0.648 E: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal-backports/InRelease 403 Forbidden [IP: 185.125.190.36 80] #6 0.648 E: The repository 'http://archive.ubuntu.com/ubuntu focal-backports InRelease' is not signed. ------ executor failed running [/bin/sh -c : && apt-get update && rm -rf /var/cache/apk/* && apt-get clean && :]: exit code: 100
内容的提问来源于stack exchange,提问作者Harith Azwar
相关产品推荐
相关产品推荐

