admin管理员组

文章数量:1401407

RUN pip install git+https://${GITHUB_TOKEN}@github//packages.git#egg=mypackage&subdirectory=mypackage is not working in my Dockerfile

This is my Dockerfile

FROM python:3.9-slim

COPY . /app

WORKDIR /app

RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*

RUN pip install --no-cache-dir -r requirements.txt

# Accept GITHUB_TOKEN as a build argument
ARG GITHUB_TOKEN

RUN echo $GITHUB_TOKEN

# Fail if GITHUB_TOKEN is not set
RUN test -n "$GITHUB_TOKEN" || (echo "ERROR: GITHUB_TOKEN is not set" && exit 1)

RUN pip install git+https://${GITHUB_TOKEN}@github/<username>/packages.git#egg=mypackage&subdirectory=mypackage

When the image is built, all packages in requirements.txt are successfully installed, however the github mypackage cannot be found when i try to import it in my code.

Note. the GITHUB_TOKEN is being successfully passed to Docker build in the cloud build step:

'--build-arg', 'GITHUB_TOKEN=${_GITHUB_TOKEN}'

And the pip installation works if I add the github package line to requirements.txt (with hard coded token)

Im wondering if the package is being pip installed somewhere unexpected. Any thoughts?

RUN pip install git+https://${GITHUB_TOKEN}@github//packages.git#egg=mypackage&subdirectory=mypackage is not working in my Dockerfile

This is my Dockerfile

FROM python:3.9-slim

COPY . /app

WORKDIR /app

RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*

RUN pip install --no-cache-dir -r requirements.txt

# Accept GITHUB_TOKEN as a build argument
ARG GITHUB_TOKEN

RUN echo $GITHUB_TOKEN

# Fail if GITHUB_TOKEN is not set
RUN test -n "$GITHUB_TOKEN" || (echo "ERROR: GITHUB_TOKEN is not set" && exit 1)

RUN pip install git+https://${GITHUB_TOKEN}@github/<username>/packages.git#egg=mypackage&subdirectory=mypackage

When the image is built, all packages in requirements.txt are successfully installed, however the github mypackage cannot be found when i try to import it in my code.

Note. the GITHUB_TOKEN is being successfully passed to Docker build in the cloud build step:

'--build-arg', 'GITHUB_TOKEN=${_GITHUB_TOKEN}'

And the pip installation works if I add the github package line to requirements.txt (with hard coded token)

Im wondering if the package is being pip installed somewhere unexpected. Any thoughts?

Share Improve this question edited Mar 24 at 15:58 President James K. Polk 42.1k29 gold badges109 silver badges145 bronze badges asked Mar 22 at 16:02 pablowilks2pablowilks2 3397 silver badges21 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Your question is not a minimal repro and thus difficult for us to help.

I am unable to repro your issue with an attempt at repro'ing it:

FROM ghcr.io/astral-sh/uv:debian-slim

RUN apt-get update && \
    apt-get install -y git && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Instead of `uv add`, use `uv venv` and install both packages using `uv pip install`
# Flask for a conventional install
# Requests for a pip install git+https example
RUN uv init && \
    uv venv && \
    uv pip install flask && \
    uv pip install git+https://github/psf/requests.git

COPY main.py main.py

ENTRYPOINT ["uv","run","main.py"]

And: main.py:

def main():
    for library_name in ["flask","requests"]:
        try:
            __import__(library_name)
            print(f"Found: {library_name}")
        except ImportError:
            print(f"Not found: {library_name}")


if __name__ == "__main__":
    main()

And:

Q="79527704"

podman build \
--tag=stackoverflow:${Q} \
--file=${PWD}/Dockerfile \
${PWD}

podman run \
--interactive --tty --rm \
--name=${Q} \
stackoverflow:${Q}

Yields:

Found: flask
Found: requests

Both packages are available as expected.

Perhaps try enumerating site-packages in the container file:

RUN ls -la /path/to/site-packages

本文标签: pythonWhy is RUN pip install from Github not working in my DockerfileStack Overflow