Bad Request(400)message every time I try to build my Docker Ubuntu 16:04 image

pw136qt2  于 2023-03-29  发布在  Docker
关注(0)|答案(3)|浏览(375)

我试图构建一个docker镜像,要求在requirements.txt中指定。然而,在尝试构建文件时,我得到以下错误:

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]

我已经尝试改变镜像,我已经检查了cat /etc/apt/sources.list的输出,我已经尝试添加标志--fix-missing并尝试使用--no-cache构建镜像,但都无济于事。
下面是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 . /

到目前为止,我发现的上述解决方案都无法解决这个问题。

vtwuwzda

vtwuwzda1#

我找到了一个帮助我的解决方案:https://www.kubuntuforums.net/showthread.php?57567-Ubuntu-problems-on-update
你可以让apt-get重新生成列表缓存,使用:

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
icnyk63a

icnyk63a2#

我也犯了同样的错误。这是我自己造成的。
我已经设置了终端来拦截(和代理)所有网络流量。关闭env变量修复了Docker Build:

unset https_proxy
1cosmwyk

1cosmwyk3#

我得到这些错误的所有时间和对我来说,它因ISP和/或地理存储库而异.我通常立即运行相同的命令,它突然修复自己.也许慢DNS查找或什么.
当然,在Dockerfile中,它会失败并停止您的构建和重建,只需重新启动命令即可。
下面是我如何解决Dockerfile中的问题
像这样替换任何apt命令....
停靠文件示例

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

....

新建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
....

这里运行apt命令,如果它有错误,它最多重试5次。这对我来说99%的时间都是有效的。
希望能帮上忙。

相关问题