在python:3.8.3的docker镜像中无法通过regex找到任何包。

问题描述 投票:0回答:2

我是docker新手,我创建了一个docker镜像,我的docker文件是这样的。

FROM python:3.8.3

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
    postgresql-client \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get install -y gcc libtool-ltdl-devel xmlsec1-1.2.20 xmlsec1-devel-1.2.20 xmlsec1 openssl- 
    1.2.20 xmlsec1-openssl-devel-1.2.20 \
    && apt-get -y install curl gnupg \
    && curl -sL https://deb.nodesource.com/setup_14.x  | bash - \
    && apt-get -y install nodejs 

WORKDIR /app/

COPY . /app

RUN pip install -r production_requirements.txt \
    && front_end/noa-frontend/npm install

这个镜像被用在docker-compose.yml的应用服务中。所以当我运行docker-compose构建时,我得到了下面的错误,说它找不到包。为了安装一个python包,我想安装的依赖项就那么几个。

enter image description here

一开始,我已经运行apt-get update来更新包列表。

谁能帮我解决这个问题。

更新后的Docker文件

FROM python:3.8.3

RUN apt-get update 
RUN apt-get install -y postgresql-client\
    && apt-get install -y gcc libtool-ltdl-devel xmlsec1-1.2.20 xmlsec1- 
    devel-1.2.20 xmlsec1 openssl-1.2.20 xmlsec1-openssl-devel-1.2.20 \
    && apt-get -y install curl gnupg \
    && curl -sL https://deb.nodesource.com/setup_14.x  | bash - \
    && apt-get -y install nodejs

WORKDIR /app/

COPY . /app

RUN pip install -r production_requirements.txt \
    && front_end/noa-frontend/npm install
python docker ubuntu docker-compose apt-get
2个回答
2
投票

你正在尝试使用 apt-get install 之后 rm -rf /var/lib/apt/lists/*. 这保证不会有好结果。试着把... rm 命令,看看是否有帮助。如果你真的需要减小图像的大小,那就把它放在 rm 命令作为运行语句中的最后一条命令。

如果你真的想减小图像大小,那么可以尝试使用 python:3.8-slimpython:3.8-alpine. Alpine是一个不同于Ubuntu默认的操作系统,但它的软件包管理器可以被告知不要在本地缓存文件。

FROM python:3.8-alpine

RUN apk add --no-cache postgresql-client
RUN apk add --no-cache gcc libtool-ltdl-devel xmlsec1-1.2.20 xmlsec1-devel-1.2.20 xmlsec1 \
    openssl-1.2.20 xmlsec1-openssl-devel-1.2.20
RUN apk add --no-cache curl gnupg
RUN apk add --no-cache  nodejs 
RUN curl -sL https://deb.nodesource.com/setup_14.x  | bash -


WORKDIR /app/

COPY . /app

RUN pip install -r production_requirements.txt \
    && front_end/noa-frontend/npm install

某些软件可能会以不同的软件包名称提供,所以你必须检查出来。


2
投票

指令 rm -rf /var/lib/apt/lists/* 或多或少是否定的 apt-get update. 之后APT就不能再访问可用包的列表了。将 rm 到最后(也许可以考虑使用更安全的 apt-get clean all).

© www.soinside.com 2019 - 2024. All rights reserved.