构建 docker 图像时某些包出现 404 错误

404 error for some packages when building docker image

在为 gitlab runner 基础图像构建 docker 图像时出现错误:

ERRO[2021-12-29T09:46:32Z] Application execution failed                  PID=6622 error="executing the script on the remote host: executing script on container with IP \"3.x.x.x\": connecting to server: connecting to server \"3.x.x.x:x\" as user \"root\": dial tcp 3.x.x.x:x: connect: connection refused"
ERROR: Job failed (system failure): prepare environment: exit status 2. Check https://docs.gitlab.com/runner/shells/index.html#shell-profile-loading for more information

Docker 文件:

FROM registry.gitlab.com/tmaczukin-test-projects/fargate-driver-debian:latest
RUN apt-get install -y wget && \
    apt-get install -y python3-pip && \
    wget https://releases.hashicorp.com/terraform/0.12.24/terraform_0.12.24_linux_amd64.zip && \
    unzip terraform_0.12.24_linux_amd64.zip
    mv terraform /usr/local/bin && \
    chmod -R 777 /usr/local/bin

我假设标题中提到的错误来自 apt-get install 命令。您应该先 运行 和 apt-get update 才能获得更新的软件包列表。否则 apt 将寻找过时状态的包(无论何时创建基础映像)。您也可以 merge the install commands and include a cleanup of temporary files in the same step to reduce layer size.

FROM registry.gitlab.com/tmaczukin-test-projects/fargate-driver-debian:latest
RUN apt-get update && \
    apt-get install -y \
      python3-pip \
      wget && \
    wget https://releases.hashicorp.com/terraform/0.12.24/terraform_0.12.24_linux_amd64.zip && \
    unzip terraform_0.12.24_linux_amd64.zip
    mv terraform /usr/local/bin && \
    chmod -R 777 /usr/local/bin && \
    rm terraform_0.12.24_linux_amd64.zip && \
    rm -rf /var/lib/apt/lists/*