Home > Back-end >  '403 Forbidden' apt-get update Ubuntu Dockerfile
'403 Forbidden' apt-get update Ubuntu Dockerfile

Time:12-28

I am new to Docker, currently trying to test ping google.com within Docker container (WSL2 Ubuntu 20.04 and Docker desktop).

I am trying to build an image with Ubuntu:20.04. When it comes to 'RUN apt-get update', it failed to fetch and return 'E: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy/InRelease 403 Forbidden [IP: 91.189.91.39 80]'.

Also, I have built another image with Alpine:latest and 'RUN apk update' but the build was success and execute as expected. Further, 'apt-get update' works just fine inside WSL2.

These are the things that I tried (based on related problems on SO) but returns the same error:-

  • change DNS within /etc/docker/daemon.json
  • change the 'http' to 'ftp' to 'https' within /etc/apt/source.lists
  • install apt-transport-https
  • update apt mirrors accordingly to my region
  • upgrade WSL2 dist to release 22.04 jammy
  • remove all files within /var/lib/apt/lists/ and apt-get update
  • reinstall 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 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

CodePudding user response:

Analysing your error message it seems to me to be an issue with the docker cache.

Look after the error, you see that there is a probleme with the signature executing apt update.

You said you installed Docker-desktop. Have you removed everything before? Reset to factory settings? Clean all?

docker rm -vf $(docker ps -a -q)
docker rmi -f $(docker images -a -q)

should delete also all

Your alpine image is executed well, because it does not update anything from the ubuntu repository which is generating the issue. (as alpine is a different linux distro)

You dont need to edit dns settings or anything else.

I tested your image, it is working fine.

Think, when you build the docker image it is not using your local wsl distro. It uses the Ubuntu version in the image itselfs, which comes from

FROM ubuntu:20.04

To check if it is related to the docker cache you can also try

FROM ubuntu:22.04

Another thing you can also add a .dockerignore file.

And inside put the folders where docker should ignore the cache when building the image. Find more info here:

https://www.techrepublic.com/article/what-is-a-dockerignore-file-and-why-you-should-be-using-them/

Please let me know if this could resolve your issue.

CodePudding user response:

Can you add:

apt-get --allow-releaseinfo-change update

before apt-update command

  • Related