share
Unix & LinuxBad Request 400 message for apt-get install every time I try to build my Docker Ubuntu 16:04 image
[+4] [1] Lord Sidd
[2020-04-17 18:08:19]
[ ubuntu apt docker ]
[ https://unix.stackexchange.com/questions/580762/bad-request-400-message-for-apt-get-install-every-time-i-try-to-build-my-docker ]

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 "y2jsiddajri@gmail.com"

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.

Does the host machine have internet access? - ctrl-alt-delor
Yes it does. Ping works and so does accessing the web through a browser. - Lord Sidd
I've started getting a similar problem the last ~week. Only seems to happen in docker builds, and happens unreliably - I've had a variety of repos and packages fail at a variety of times. I'm running Ubuntu 18. I've found if I run and rerun the build, eventually it works. - Andy Jones
[+1] [2021-03-09 21:27:29] Eric Horne

I was able to work around this very frustrating issue by setting the apt HTTP proxy to use my internet proxy directly. It is not clear why the invisible proxy works for some packages but not others, but explicitly setting the proxy addressed the issue.

See Cannot install packages with apt-get update in debian (Proxy) [1] for examples of setting the proxy.

I used the /etc/apt/apt.conf.d/30proxy.conf method by creating a file that contained:

Acquire::http { Proxy "http://192.168.0.1:3128" }

where http://192.168.0.1:3128 is the squid proxy.

[1] https://unix.stackexchange.com/questions/570906/cannot-install-packages-with-apt-get-update-in-debian-proxy

1