Search code examples
pythondockerpipdockerfilevscode-devcontainer

pip list not showing packages installed in dockerfile in dev container


I'm currently trying to develop a Python application inside a container and am using Docker. I'm under the impression that the packages installed through the dockerfile should be available in the container but when running pip list it doesn't show any of the packages mentioned in the dockerfile. Here's my 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/[email protected]#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"]

and here's my 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"
        }
    }
}

Because of this I can't develop inside the container unless I install again the packages in the container itself, which were supposed to be already installed when building the container.

The app does work though when developing on my local system and using docker build and docker run


Solution

  • without build logs its hard to say for sure but i believe youre installing a second version of python3.10 (separate from the one already installed by your base image)

    try setting

    "version": "system"
    
    

    youll likely find some useful info in the install script for that feature https://github.com/devcontainers/features/blob/main/src/python/install.sh

    also

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