pip列表不显示安装在dockerfile中的软件包

icomxhvb  于 2023-04-20  发布在  Docker
关注(0)|答案(1)|浏览(130)

我目前正在尝试在容器中开发一个Python应用程序,并且正在使用Docker。我的印象是,通过dockerfile安装的包应该在容器中可用,但当运行pip list时,它不会显示dockerfile中提到的任何包。这是我的dockerfile

FROM python:3.10-slim-buster

# Update package lists
RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 gcc g++ git build-essential libpoppler-cpp-dev pkg-config poppler-utils tesseract-ocr libtesseract-dev -y

# Make working directories
RUN  mkdir -p  /intellecs-backend
WORKDIR  /intellecs-backend

# Copy the requirements.txt file to the container
COPY requirements.txt .

# Install dependencies
RUN pip install --upgrade pip

RUN pip install torch torchvision torchaudio

RUN pip install -r requirements.txt

RUN pip install 'git+https://github.com/facebookresearch/detectron2.git@v0.4#egg=detectron2'

# Copy the .env file to the container
COPY .env .

# Copy every file in the source folder to the created working directory
COPY  . .

# Expose the port that the application will run on
EXPOSE 8000

# Start the application
CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]

这是我的devcontainer.json:

// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile
{
    "name": "Existing Dockerfile",
    "build": {
        // Sets the run context to one level up instead of the .devcontainer folder.
        "context": "..",
        // Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
        "dockerfile": "../dockerfile"
    },
    "features": {
        "ghcr.io/devcontainers/features/python:1": {
            "installTools": true,
            "version": "3.10"
        }
    }
}

因此,我不能在容器中开发,除非我再次安装容器本身中的包,这些包应该在构建容器时已经安装。
在我的本地系统上开发并使用docker builddocker run时,该应用程序确实可以工作

d7v8vwbk

d7v8vwbk1#

没有构建日志很难说,但我相信您正在安装python3.10的第二个版本(与您的基础映像已经安装的版本分开)
试调

"version": "system"

您可能会在该特性https://github.com/devcontainers/features/blob/main/src/python/install.sh的安装脚本中找到一些有用的信息。

https://containers.dev/implementors/features/

相关问题