[Python] ReadTimeoutError while packaging my python project with docker

Discussão em 'Python' iniciado por Stack, Abril 22, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working on a python project. It is a CLI based project and I want to package this project with docker. I create a .Docker file and include the content as per my project.

    # Use an official Python runtime as a parent image
    FROM python:3.12-slim

    # Set the working directory in the container
    WORKDIR /app

    # Copy the requirements file into the container at /app
    COPY requirements.txt .

    # Install any dependencies
    RUN pip install --default-timeout=100 --retries=10 --no-cache-dir -r requirements.txt

    # Copy the project files into the container
    COPY . .

    # Set the entry point to the Python interpreter
    ENTRYPOINT ["python"]

    # Set the default command to run your CLI script (without any specific action)
    CMD ["CLI.py"]


    The things is, when I run the command docker build -t trustvault ., it start processing to package it but when it reach at the line RUN pip install --default-timeout=100 --retries=10 --no-cache-dir -r requirements.txt, it throw ReadTimeoutError.

    here's the requirements.txt file.

    watchdog==6.0.0
    joblib==1.4.2
    scikit-learn==1.6.1
    pandas==2.2.3
    mysql-connector-python==9.3.0
    python-dotenv==1.1.0


    you can find the complete error message below:

    [+] Building 128.2s (8/9) docker:default
    => [internal] load build definition from Dockerfile 0.0s
    => => transferring dockerfile: 586B 0.0s
    => [internal] load metadata for docker.io/library/python:3.12-slim 0.8s
    => [internal] load .dockerignore 0.0s
    => => transferring context: 113B 0.0s
    => [1/5] FROM docker.io/library/python:3.12-slim@sha256:85824326bc4ae27a1abb5bc0dd9e08847aa5fe73d8afb593b1b45b7cb4180f57 0.0s
    => [internal] load build context 0.0s
    => => transferring context: 11.46kB 0.0s
    => CACHED [2/5] WORKDIR /app 0.0s
    => [3/5] COPY requirements.txt . 0.1s
    => ERROR [4/5] RUN pip install --default-timeout=100 --retries=10 --no-cache-dir -r requirements.txt 127.1s
    ------
    > [4/5] RUN pip install --default-timeout=100 --retries=10 --no-cache-dir -r requirements.txt:
    3.113 Collecting watchdog==6.0.0 (from -r requirements.txt (line 1))
    3.266 Downloading watchdog-6.0.0-py3-none-manylinux2014_x86_64.whl.metadata (44 kB)
    3.363 Collecting joblib==1.4.2 (from -r requirements.txt (line 2))
    3.452 Downloading joblib-1.4.2-py3-none-any.whl.metadata (5.4 kB)
    3.742 Collecting scikit-learn==1.6.1 (from -r requirements.txt (line 3))
    3.811 Downloading scikit_learn-1.6.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (18 kB)
    4.126 Collecting pandas==2.2.3 (from -r requirements.txt (line 4))
    4.155 Downloading pandas-2.2.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (89 kB)
    4.403 Collecting mysql-connector-python==9.3.0 (from -r requirements.txt (line 5))
    4.466 Downloading mysql_connector_python-9.3.0-cp312-cp312-manylinux_2_28_x86_64.whl.metadata (7.5 kB)
    4.518 Collecting python-dotenv==1.1.0 (from -r requirements.txt (line 6))
    4.552 Downloading python_dotenv-1.1.0-py3-none-any.whl.metadata (24 kB)
    4.933 Collecting numpy>=1.19.5 (from scikit-learn==1.6.1->-r requirements.txt (line 3))
    4.966 Downloading numpy-2.2.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (62 kB)
    5.479 Collecting scipy>=1.6.0 (from scikit-learn==1.6.1->-r requirements.txt (line 3))
    5.520 Downloading scipy-1.15.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (61 kB)
    5.612 Collecting threadpoolctl>=3.1.0 (from scikit-learn==1.6.1->-r requirements.txt (line 3))
    5.652 Downloading threadpoolctl-3.6.0-py3-none-any.whl.metadata (13 kB)
    5.713 Collecting python-dateutil>=2.8.2 (from pandas==2.2.3->-r requirements.txt (line 4))
    5.808 Downloading python_dateutil-2.9.0.post0-py2.py3-none-any.whl.metadata (8.4 kB)
    6.072 Collecting pytz>=2020.1 (from pandas==2.2.3->-r requirements.txt (line 4))
    6.330 Downloading pytz-2025.2-py2.py3-none-any.whl.metadata (22 kB)
    6.399 Collecting tzdata>=2022.7 (from pandas==2.2.3->-r requirements.txt (line 4))
    6.791 Downloading tzdata-2025.2-py2.py3-none-any.whl.metadata (1.4 kB)
    6.840 Collecting six>=1.5 (from python-dateutil>=2.8.2->pandas==2.2.3->-r requirements.txt (line 4))
    6.872 Downloading six-1.17.0-py2.py3-none-any.whl.metadata (1.7 kB)
    6.929 Downloading watchdog-6.0.0-py3-none-manylinux2014_x86_64.whl (79 kB)
    7.000 Downloading joblib-1.4.2-py3-none-any.whl (301 kB)
    7.138 Downloading scikit_learn-1.6.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.1 MB)
    17.22 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 13.1/13.1 MB 2.0 MB/s eta 0:00:00
    17.26 Downloading pandas-2.2.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.7 MB)
    126.6 ━━━━━━━━━━━━━╸ 4.5/12.7 MB 1.9 MB/s eta 0:00:05
    126.8 ERROR: Exception:
    126.8 Traceback (most recent call last):
    126.8 File "/usr/local/lib/python3.12/site-packages/pip/_vendor/urllib3/response.py", line 438, in _error_catcher
    126.8 yield
    126.8 File "/usr/local/lib/python3.12/site-packages/pip/_vendor/urllib3/response.py", line 561, in read
    126.8 data = self._fp_read(amt) if not fp_closed else b""
    126.8 ^^^^^^^^^^^^^^^^^^
    126.8 File "/usr/local/lib/python3.12/site-packages/pip/_vendor/urllib3/response.py", line 527, in _fp_read
    126.8 return self._fp.read(amt) if amt is not None else self._fp.read()
    126.8 ^^^^^^^^^^^^^^^^^^
    126.8 File "/usr/local/lib/python3.12/http/client.py", line 479, in read
    126.8 s = self.fp.read(amt)
    126.8 ^^^^^^^^^^^^^^^^^
    126.8 File "/usr/local/lib/python3.12/socket.py", line 720, in readinto
    126.8 return self._sock.recv_into(b)
    126.8 ^^^^^^^^^^^^^^^^^^^^^^^
    126.8 File "/usr/local/lib/python3.12/ssl.py", line 1251, in recv_into
    126.8 return self.read(nbytes, buffer)
    126.8 ^^^^^^^^^^^^^^^^^^^^^^^^^
    126.8 File "/usr/local/lib/python3.12/ssl.py", line 1103, in read
    126.8 return self._sslobj.read(len, buffer)
    126.8 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    126.8 TimeoutError: The read operation timed out
    126.8
    126.8 During handling of the above exception, another exception occurred:
    126.8
    126.8 Traceback (most recent call last):
    126.8 File "/usr/local/lib/python3.12/site-packages/pip/_internal/cli/base_command.py", line 106, in _run_wrapper
    126.8 status = _inner_run()
    126.8 ^^^^^^^^^^^^
    126.8 File "/usr/local/lib/python3.12/site-packages/pip/_internal/cli/base_command.py", line 97, in _inner_run
    126.8 return self.run(options, args)
    126.8 ^^^^^^^^^^^^^^^^^^^^^^^
    126.8 File "/usr/local/lib/python3.12/site-packages/pip/_internal/cli/req_command.py", line 67, in wrapper
    126.8 return func(self, options, args)
    126.8 ^^^^^^^^^^^^^^^^^^^^^^^^^
    126.8 File "/usr/local/lib/python3.12/site-packages/pip/_internal/commands/install.py", line 386, in run
    126.8 requirement_set = resolver.resolve(
    126.8 ^^^^^^^^^^^^^^^^^
    126.8 File "/usr/local/lib/python3.12/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 179, in resolve
    126.8 self.factory.preparer.prepare_linked_requirements_more(reqs)
    126.8 File "/usr/local/lib/python3.12/site-packages/pip/_internal/operations/prepare.py", line 554, in prepare_linked_requirements_more
    126.8 self._complete_partial_requirements(
    126.8 File "/usr/local/lib/python3.12/site-packages/pip/_internal/operations/prepare.py", line 469, in _complete_partial_requirements
    126.8 for link, (filepath, _) in batch_download:
    126.8 ^^^^^^^^^^^^^^
    126.8 File "/usr/local/lib/python3.12/site-packages/pip/_internal/network/download.py", line 184, in __call__
    126.8 for chunk in chunks:
    126.8 ^^^^^^
    126.8 File "/usr/local/lib/python3.12/site-packages/pip/_internal/cli/progress_bars.py", line 55, in _rich_progress_bar
    126.8 for chunk in iterable:
    126.8 ^^^^^^^^
    126.8 File "/usr/local/lib/python3.12/site-packages/pip/_internal/network/utils.py", line 65, in response_chunks
    126.8 for chunk in response.raw.stream(
    126.8 ^^^^^^^^^^^^^^^^^^^^
    126.8 File "/usr/local/lib/python3.12/site-packages/pip/_vendor/urllib3/response.py", line 622, in stream
    126.8 data = self.read(amt=amt, decode_content=decode_content)
    126.8 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    126.8 File "/usr/local/lib/python3.12/site-packages/pip/_vendor/urllib3/response.py", line 560, in read
    126.8 with self._error_catcher():
    126.8 ^^^^^^^^^^^^^^^^^^^^^
    126.8 File "/usr/local/lib/python3.12/contextlib.py", line 158, in __exit__
    126.8 self.gen.throw(value)
    126.8 File "/usr/local/lib/python3.12/site-packages/pip/_vendor/urllib3/response.py", line 443, in _error_catcher
    126.8 raise ReadTimeoutError(self._pool, None, "Read timed out.")
    126.8 pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
    ------
    Dockerfile:11
    --------------------
    9 |
    10 | # Install any dependencies
    11 | >>> RUN pip install --default-timeout=100 --retries=10 --no-cache-dir -r requirements.txt
    12 |
    13 | # Copy the project files into the container
    --------------------
    ERROR: failed to solve: process "/bin/sh -c pip install --default-timeout=100 --retries=10 --no-cache-dir -r requirements.txt" did not complete successfully: exit code: 2


    I've tried many solutions for installation line but every time I got the same error.

    how can i resolve it?

    Continue reading...

Compartilhe esta Página