Reputation: 41
I am attempting to build a docker image with the requirements specified in requirements.txt
. However, upon trying to build the file, I get the following error:
E: Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/main/l/linux-atm/libatm1_2.5.1-1.5_amd64.deb 400 Bad Request [IP: 91.189.91.39 80]
E: Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/main/p/popt/libpopt0_1.16-10_amd64.deb 400 Bad Request [IP: 91.189.91.39 80]
E: Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/main/libc/libcap-ng/libcap-ng0_0.7.7-1_amd64.deb 400 Bad Request [IP: 91.189.91.39 80]
I have attempted to change the mirror, I have checked the output of cat /etc/apt/sources.list, I have tried to add the flag --fix-missing
and tried to build the image with --no-cache
all to no avail.
Here is the Dockerfile:
# Base image
FROM ubuntu:16.04
MAINTAINER Siddhanth Ajri "[email protected]"
RUN cat /etc/apt/sources.list
# Changing to US archives of UBUNTU
RUN sed -i'' 's/archive\.ubuntu\.com/us\.archive\.ubuntu\.com/' /etc/apt/sources.list
# Install dependencies
RUN apt-get update && apt-get install -y \
software-properties-common \
curl \
git
#RUN add-apt-repository universe
RUN apt-get update && apt-get install -y \
curl \
git
RUN apt-get install python3.7
RUN apt-get install python3-pip
# Upgrade pip to 20.x
RUN pip3 install -U pip
COPY ./requirements.txt /requirements.txt
WORKDIR /
RUN pip3 install -r requirements.txt
COPY . /
None of the mentioned solutions I've found so far have been able to fix this issue for me.
Upvotes: 3
Views: 5616
Reputation: 59
I get these errors all the time and for me it varies by ISP and/or geographic repos. I usually run the same command immediately and it suddenly fixes itself. Maybe slow DNS Lookup or something.
Of course inside a Dockerfile it fails and stops you building and rebuilding simply starts the command over again.
Heres how i solved the issue in Dockerfile
Replace any apt commands like so....
Example Dockerfile
FROM ubuntu:20.04
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y apt-utils software-properties-common nano wget curl
RUN apt install apache2 mariadb-server -y
....
New Dockerfile
FROM ubuntu:20.04
RUN set -eux; \
for i in $(seq 1 5); do \
if apt-get update && apt-get upgrade -y; then \
break; \
else \
echo "Error: apt-get failed (attempt $i of 5). Retrying..." >&2; \
sleep 1; \
fi; \
done; \
if [ "$i" = 5 ]; then \
echo "Error: apt-get failed after 5 attempts." >&2; \
exit 1; \
fi
RUN set -eux; \
for i in $(seq 1 5); do \
if apt-get install -y apt-utils software-properties-common nano wget curl; then \
break; \
else \
echo "Error: apt-get failed (attempt $i of 5). Retrying..." >&2; \
sleep 1; \
fi; \
done; \
if [ "$i" = 5 ]; then \
echo "Error: apt-get failed after 5 attempts." >&2; \
exit 1; \
fi
RUN set -eux; \
for i in $(seq 1 5); do \
if apt install apache2 mariadb-server -y; then \
break; \
else \
echo "Error: apt-get failed (attempt $i of 5). Retrying..." >&2; \
sleep 1; \
fi; \
done; \
if [ "$i" = 5 ]; then \
echo "Error: apt-get failed after 5 attempts." >&2; \
exit 1; \
fi
....
Here the apt command is run and if it has an error it retries up to a maximum of 5 times. This has worked for me 99% of the time.
Hope it helps someone.
Upvotes: 1
Reputation: 4085
I hit the same error. It was self-inflicted.
I had set up my terminal to intercept ( and proxy ) all network traffic. Turning that env variable off fixed the Docker Build:
unset https_proxy
Upvotes: 0
Reputation: 11
I found a solution which helped me here: https://www.kubuntuforums.net/showthread.php?57567-Ubuntu-problems-on-update
You can let apt-get to regenerate lists cache using:
sudo apt-get clean
cd /var/lib/apt
sudo mv lists lists.old
sudo mkdir -p lists/partial
sudo apt-get clean
sudo apt-get update
Upvotes: 1