skip to Main Content

I am trying to build the Docker image of a FastApi application (i work on MacOs, with Docker version 2.2.0.3 and engine 19.03.5).

docker build --no-cache -t name:latest .

When I build the Docker image I have an issue with pip install.
When I remove all calls to pip, everything runs.

My Dockerfile:

# syntax=docker/dockerfile:1
FROM python:3.9
LABEL maintainer="X Y <[email protected]>"

COPY ./app /app
WORKDIR /app/

ENV VIRTUAL_ENV=/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

# Install dependencies:
COPY requirements.txt .
# RUN pip3 install --no-cache-dir pytest==7.4.2
#RUN pip install --upgrade pip
RUN python3 -m pip install -r ./requirements.txt

COPY ./start.sh /start.sh
RUN chmod +x /start.sh

COPY ./gunicorn_conf.py /gunicorn_conf.py

COPY ./start-reload.sh /start-reload.sh
RUN chmod +x /start-reload.sh

COPY ./app /app
WORKDIR /app/

ENV PYTHONPATH=/app

EXPOSE 8000

And the error:

(venv) alexpsq@MacBook-Pro-Alex backend % docker build --no-cache -t name:latest . &> build.log
(venv) alexpsq@MacBook-Pro-Alex backend % cat build.log 
#2 [internal] load build definition from Dockerfile
#2 transferring dockerfile: 37B done
#2 DONE 0.0s

#1 [internal] load .dockerignore
#1 transferring context: 34B done
#1 DONE 0.0s

#3 resolve image config for docker.io/docker/dockerfile:1
#3 DONE 1.9s

#4 docker-image://docker.io/docker/dockerfile:1@sha256:XXX...
#4 CACHED

#5 [internal] load build definition from Dockerfile
#5 transferring dockerfile: 37B done
#5 DONE 0.0s

#6 [internal] load metadata for docker.io/library/python:3.9
#6 DONE 0.0s

#7 [internal] load .dockerignore
#7 DONE 0.0s

#8 [ 1/13] FROM docker.io/library/python:3.9
#8 CACHED

#9 [internal] load build context
#9 transferring context: 1.26kB done
#9 DONE 0.0s

#10 [ 2/13] COPY ./app /app
#10 DONE 0.0s

#11 [ 3/13] WORKDIR /app/
#11 DONE 0.0s

#12 [ 4/13] RUN python3 -m venv /venv
#12 DONE 3.4s

#13 [ 5/13] COPY requirements.txt .
#13 DONE 0.0s

#14 [ 6/13] RUN python3 -m pip install -r ./requirements.txt
#14 0.859 Collecting pytest==7.4.2
#14 1.192   Downloading pytest-7.4.2-py3-none-any.whl (324 kB)
#14 1.198 ERROR: Exception:
#14 1.198 Traceback (most recent call last):
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_internal/cli/base_command.py", line 160, in exc_logging_wrapper
#14 1.198     status = run_func(*args)
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_internal/cli/req_command.py", line 247, in wrapper
#14 1.198     return func(self, options, args)
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_internal/commands/install.py", line 419, in run
#14 1.198     requirement_set = resolver.resolve(
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 92, in resolve
#14 1.198     result = self._result = resolver.resolve(
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_vendor/resolvelib/resolvers.py", line 481, in resolve
#14 1.198     state = resolution.resolve(requirements, max_rounds=max_rounds)
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_vendor/resolvelib/resolvers.py", line 348, in resolve
#14 1.198     self._add_to_criteria(self.state.criteria, r, parent=None)
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_vendor/resolvelib/resolvers.py", line 172, in _add_to_criteria
#14 1.198     if not criterion.candidates:
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_vendor/resolvelib/structs.py", line 151, in __bool__
#14 1.198     return bool(self._sequence)
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 155, in __bool__
#14 1.198     return any(self)
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 143, in <genexpr>
#14 1.198     return (c for c in iterator if id(c) not in self._incompatible_ids)
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/found_candidates.py", line 47, in _iter_built
#14 1.198     candidate = func()
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 206, in _make_candidate_from_link
#14 1.198     self._link_candidate_cache[link] = LinkCandidate(
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 297, in __init__
#14 1.198     super().__init__(
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 162, in __init__
#14 1.198     self.dist = self._prepare()
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 231, in _prepare
#14 1.198     dist = self._prepare_distribution()
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 308, in _prepare_distribution
#14 1.198     return preparer.prepare_linked_requirement(self._ireq, parallel_builds=True)
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_internal/operations/prepare.py", line 491, in prepare_linked_requirement
#14 1.198     return self._prepare_linked_requirement(req, parallel_builds)
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_internal/operations/prepare.py", line 536, in _prepare_linked_requirement
#14 1.198     local_file = unpack_url(
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_internal/operations/prepare.py", line 166, in unpack_url
#14 1.198     file = get_http_url(
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_internal/operations/prepare.py", line 107, in get_http_url
#14 1.198     from_path, content_type = download(link, temp_dir.path)
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_internal/network/download.py", line 147, in __call__
#14 1.198     for chunk in chunks:
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_internal/cli/progress_bars.py", line 52, in _rich_progress_bar
#14 1.198     with progress:
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_vendor/rich/progress.py", line 1169, in __enter__
#14 1.198     self.start()
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_vendor/rich/progress.py", line 1160, in start
#14 1.198     self.live.start(refresh=True)
#14 1.198   File "/venv/lib/python3.9/site-packages/pip/_vendor/rich/live.py", line 132, in start
#14 1.198     self._refresh_thread.start()
#14 1.198   File "/usr/local/lib/python3.9/threading.py", line 899, in start
#14 1.198     _start_new_thread(self._bootstrap, ())
#14 1.198 RuntimeError: can't start new thread
#14 1.490 
#14 1.490 [notice] A new release of pip is available: 23.0.1 -> 23.2.1
#14 1.490 [notice] To update, run: pip install --upgrade pip
#14 ERROR: executor failed running [/bin/sh -c python3 -m pip install -r ./requirements.txt]: runc did not terminate sucessfully
------
 > [ 6/13] RUN python3 -m pip install -r ./requirements.txt:
------
failed to solve with frontend dockerfile.v0: failed to solve with frontend gateway.v0: rpc error: code = Unknown desc = failed to build LLB: executor failed running [/bin/sh -c python3 -m pip install -r ./requirements.txt]: runc did not terminate sucessfully

Thank you for your help !!

I tried various ways to pip install :

# RUN pip3 install --no-cache-dir pytest==7.4.2.         # Nothing works
# RUN pip install --upgrade pip                          # Nothing works 
RUN python3 -m pip install -r ./requirements.txt         # Nothing works

I tried to install a single package, it did not worked.
I tried to replace FROM python:3.9 with FROM python:3.9-slim, it did not worked.

Also tried to with and without the args in the following CLI:

docker build --network=host -f Dockerfile --shm-size 10g --platform linux/amd64 --no-cache -t name:latest .

When i removed the buildkit with :

export DOCKER_BUILDKIT=0
export COMPOSE_DOCKER_CLI_BUILD=0

i have the same issue except for:

[...]
RuntimeError: can't start new thread

[notice] A new release of pip is available: 23.0.1 -> 23.2.1
[notice] To update, run: pip install --upgrade pip
The command '/bin/sh -c python3 -m pip install --no-cache-dir --upgrade pip' returned a non-zero code: 2

2

Answers


  1. Chosen as BEST ANSWER

    I had to update docker... (uninstall and re-install)


  2. It does look like an error starting a thread. There is a generic answer for this RuntimeError at
    error: can't start new thread

    This GitHub article might be interesting too: https://github.com/pypa/pip/issues/1166

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search