Search code examples
pythondockerpipenv

a strange file created when running a docker


I tried to run a docker container, but such an exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/pipenv", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/pipenv/cli/options.py", line 58, in main
    return super().main(*args, **kwargs, windows_expand_args=False)
  File "/usr/local/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/pipenv/vendor/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/pipenv/vendor/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/pipenv/cli/command.py", line 417, in run
    do_run(
  File "/usr/local/lib/python3.8/site-packages/pipenv/routines/shell.py", line 66, in do_run
    ensure_project(
  File "/usr/local/lib/python3.8/site-packages/pipenv/utils/project.py", line 30, in ensure_project
    if project.s.PIPENV_USE_SYSTEM or project.virtualenv_exists:
  File "/usr/local/lib/python3.8/site-packages/pipenv/project.py", line 411, in virtualenv_exists
    if os.path.exists(self.virtualenv_location):
  File "/usr/local/lib/python3.8/site-packages/pipenv/project.py", line 608, in virtualenv_location
    self._virtualenv_location = self.get_location_for_virtualenv()
  File "/usr/local/lib/python3.8/site-packages/pipenv/project.py", line 433, in get_location_for_virtualenv
    return str(get_workon_home().joinpath(self.virtualenv_name))
  File "/usr/local/lib/python3.8/site-packages/pipenv/utils/shell.py", line 195, in get_workon_home
    os.makedirs(expanded_path, exist_ok=True)
  File "/usr/local/lib/python3.8/os.py", line 213, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/usr/local/lib/python3.8/os.py", line 213, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/usr/local/lib/python3.8/os.py", line 213, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/usr/local/lib/python3.8/os.py", line 223, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/nonexistent'

seems there is a file named nonexistent, but seems it doesn't exist at all from its name.

but why? why did this happen?

also, I can provide you with some details about my docker file:

ARG PYTHON_VERSION=3.8.2
FROM python:${PYTHON_VERSION}-slim as base
ENV PYTHONDONTWRITEBYTECODE=1

WORKDIR /app
ARG UID=10001
RUN adduser \
    --disabled-password \
    --gecos "" \
    --home "/nonexistent" \
    --shell "/sbin/nologin" \
    --no-create-home \
    --uid "${UID}" \
    appuser
COPY Pipfile Pipfile.lock ./
RUN pip install pipenv
RUN pipenv install --deploy --ignore-pipfile
USER appuser
COPY . .
EXPOSE 5000
CMD pipenv run python app.py

since I didn't see any error information about my files, I think it has nothing to do with my code. But I just have no idea about it. Or is there any possibility for this to happen if I merge pipenv and docker together? I'm not quite sure about this because I didn't have that many references when I did this.

I'd really appreciate it if you have any ideas.


Solution

  • /nonexistent is your own doing in

    --home "/nonexistent"
    --no-create-home
    

    pipenv is trying to create a virtualenv in that home directory, and it doesn't exist.

    You probably want to get rid of that --no-create-home (but TBH, you don't really need virtualenvs in a container at all, so pipenv install --system).