I am building a docker using the php:7.4-apache-buster image on a laptop running Debian 11.
Inside my Dockerfile, I run some apt-get update/install command some docker-php-ext-configure:
RUN apt-get update && apt-get install -y --no-install-recommends apt-utils libzip-dev libssl-dev vim \
## Zip extension
&& apt-get install -y --no-install-recommends zlib1g-dev \
&& docker-php-ext-install zip \
## gd & other image extentions
&& apt-get install -y --no-install-recommends libpng-dev libfreetype6-dev libjpeg62-turbo-dev libpng-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg && docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-configure exif && docker-php-ext-install -j$(nproc) exif \
## Other extensions & database utils
&& docker-php-ext-install mysqli pdo pdo_mysql
Then I called a script and inside it I also install some packages:
package_array=( "apt-utils" "acl" "libzip-dev" "libssl-dev" "vim" "locales" "zlib1g-dev" "libpng-dev" "libfreetype6-dev" "libjpeg62-turbo-dev" "libpng-dev" "git" "unzip" "curl" "libreoffice-base-core" "libreoffice-base-drivers" "libreoffice-core" "libreoffice-common" "libreoffice-writer" "libreoffice-calc" "libreoffice-draw" "libreoffice-impress" "python3" "ghostscript" "default-jdk" "poppler-utils" "openjdk-11-jre-headless" "cron")
for pkt in "${package_array[@]}"; do
apt-get update
echo -ne "${OK}Installation of $pkt ${RESET}"
apt-get install -y "$pkt" &>> "$deb_log_path"
ERR_CODE=$?
if [ $ERR_CODE -ne 0 ]; then
echo ""
echo -e "${FAIL}${RED_CROSS_MARK}[ERR] You will find the log here: ""$deb_log_path""${RESET}"
echo -e "\\r${FAIL}${RED_CROSS_MARK}[ERR] An error occurred installing '$pkt' (return code $ERR_CODE), exiting..${RESET}"
exit
fi
echo -e "\\r${OK}${CHECK_MARK} $pkt has been installed.${RESET}"
done
The problem is that sometimes (like 8 times out of 10) the installation or the update of packages end up with a message like this:
E: Failed to fetch http://deb.debian.org/debian/pool/main/x/xdg-utils/xdg-utils_1.1.3-1 deb10u1_all.deb Unable to connect to deb.debian.org:http: [IP: 199.232.178.132 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
It happens at random time and with random package or during update. I already tried:
- Change the sources.list with a
COPY sources.list /etc/apt/sources.list
- Rewriting the resolv.conf with public DNS:
RUN echo "nameserver 8.8.8.8" >> /etc/resolv.conf && echo "nameserver 8.8.4.4" > /etc/resolv.conf
- Add a apt update in my loop when installing my packages via the script (see the code above)
- Run all my apt-update instruction in the dockerfile on the same line
- Use a docker-compose file and add the following line:
network_mode: "host"
Nothing seems to work, sometimes my build will end up with no error and most of the times it will with an error. I already searched online for help, but even if it seems that I am not the first to experience this, nothing solve my issue
CodePudding user response:
This happened to me some times.
Try attaching the docker's network to the hosts. https://docs.docker.com/network/host/
docker run --network=host <command>
This will run docker in the host's network which has security implications that you should research.
CodePudding user response:
See http://deb.debian.org/, this should be frontend point which will route to a real backend point, as it mentioded:
The server deb.debian.org does not have packages itself, but the name has SRV records in DNS that let apt in stretch and later find places.
So, I guess it will route to different IPs during your different tries, while some ip can't be used in your network. This may could explain why sometimes it works for you while sometimes it doesn't.
As a result, I suggest you to directly use a mirror in sources.list
, see all mirrors here to find a stable one which fit your network.