当我第一次发现码头时我真的很高兴。但是我一直遇到这个问题,在这个问题中,Docker最初成功地构建了一个容器,但是如果我尝试在几个月后重新构建一个容器,它就会失败,即使我对Dockerfile和docker-compose.yml文件没有做任何更改。
我怀疑外部依赖(在这种情况下,一些cron所必需的cron包)可能变得不可访问,从而破坏了Docker。有人也遇到过这个问题吗?这是码头工人常见的问题吗?我怎么才能绕过它?
这是错误信息。
E: Failed to fetch http://deb.debian.org/debian/pool/main/m/mariadb-10.3/mariadb-common_10.3.29-0+deb10u1_all.deb 404 Not Found [IP: 151.101.54.132 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
Fetched 17.6 MB in 0s (48.6 MB/s)
ERROR: Service 'python_etls' failed to build: The command '/bin/sh -c apt-get install cron -y' returned a non-zero code: 100这是我的docker-compose.yml。
## this docker-compose file is for development/local environment
version: '3'
services:
python_etls:
container_name: python_etls
restart: always
build:
context: ./python_etls
dockerfile: Dockerfile这是我的Dockerfile。
#FROM python:3.8-slim-buster # debian gnutls28 fetch doesn't work in EC2 machine
FROM python:3.9-slim-buster
RUN apt-get update
## install
RUN apt-get install nano -y
## define working directory
ENV CONTAINER_HOME=/home/projects/python_etls
## create working directory
RUN mkdir -p $CONTAINER_HOME
## create directory to save logs
RUN mkdir -p $CONTAINER_HOME/logs
## set working directory
WORKDIR $CONTAINER_HOME
## copy source code into the container
COPY . $CONTAINER_HOME
## install python modules through pip
RUN pip install snowflake snowflake-sqlalchemy sqlalchemy pymongo dnspython numpy pandas python-dotenv xmltodict appstoreconnect boto3
# pip here is /usr/local/bin/pip, as seen when running 'which pip' in command line, and installs python packages for /usr/local/bin/python
# https://stackoverflow.com/questions/45513879/trouble-running-python-script-cron-import-error-no-module-named-tweepy
## changing timezone
ENV TZ=America/Los_Angeles
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
## scheduling with cron
## reference: https://stackoverflow.com/questions/37458287/how-to-run-a-cron-job-inside-a-docker-container
# install cron
RUN apt-get install cron -y
# Copy crontable file to the cron.d directory
COPY crontable /etc/cron.d/crontable
# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/crontable
# Apply cron job
RUN crontab /etc/cron.d/crontable
# Create the log file to be able to run tail
#RUN touch /var/log/cron.log
# Run the command on container startup
#CMD cron && tail -f /var/log/cron.log
CMD ["cron", "-f"]编辑:因此,将Docker基础图像从python:3.9-slim-buster更改为Dockerfile中的python:3.10-slim-buster可以成功构建。然而,我仍然不明白为什么它会在一开始就崩溃,以及我应该做些什么来缓解这个问题。
发布于 2021-12-21 00:44:35
您可能有这样的误解:每次尝试从同一个Dockerfile构建时,docker都会生成相同的映像。不是,也不是码头的问题空间。
当您构建映像时,您最有可能到达外部资源:包、存储库、注册表等。可能会发布安全更新,并因此删除一些旧包。包管理人员可能会请求特定库的最新版本,因此更新的发布将影响您的映像的可再现性。
您可以通过将尽可能多的依赖项的版本固定在一起来尽量减少这种影响。还有一些工具,比如nix,可以让你真正达到完全的再现性。如果这对你很重要,我会指给你那个方向。
https://stackoverflow.com/questions/70429456
复制相似问题