Setting up a Docker Container for running a flask script with Poetry won't run

Hello all,

I want to run a flask script in a docker container. I wrote this Dockerfile to build the container and use poetry to install the dependencies:

FROM python:3.10

WORKDIR /ModelToProduction

COPY pyproject.toml poetry.lock* ./

RUN pip install poetry

RUN poetry install

COPY . /ModelToProduction

# Change port if needed

EXPOSE 5000

CMD ["python", "server/main.py"]

And this is the used pyproject.toml for poetry:

[tool.poetry]
name = "ModelToProduction"
version = "0.1.0"
description = "Task 1 for course DLBDSMTP01 B.Sc. Data Science"
authors = ["Manuel Vogt <vogt.manuel@proton.me>"]

[tool.poetry.dependencies]
python = ">=3.10, <=3.11.4"
numpy = "^1.25.2"
scikit-learn = "^1.3.0"
flask = "^2.3.3"
requests = "^2.31.0"

[tool.poetry.group.dev.dependencies]
poethepoet = "^0.22.0"
black = "^23.7.0"
jupyter = "^1.0.0"

[tool.poe.tasks]
sim = "python3.11 sensor/simulate_sensors_stream.py"
serve = "python3.11 server/main.py"
gen_data = "python3.11 model/generate_artificial_dataset.py"
train_model = "python3.11 model/train_model.py"
format = "black ."

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

When I run this in a fresh venv with docker installed via pip everything seems to work:

[tavar@Nexus ModelToProduction]$ python -m venv penv
[tavar@Nexus ModelToProduction]$ source penv/bin/activate
(penv) [tavar@Nexus ModelToProduction]$ pip install docker
Collecting docker
  Downloading docker-6.1.3-py3-none-any.whl (148 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 148.1/148.1 kB 1.9 MB/s eta 0:00:00
Collecting packaging>=14.0
  Using cached packaging-23.1-py3-none-any.whl (48 kB)
Collecting requests>=2.26.0
  Using cached requests-2.31.0-py3-none-any.whl (62 kB)
Collecting urllib3>=1.26.0
  Using cached urllib3-2.0.4-py3-none-any.whl (123 kB)
Collecting websocket-client>=0.32.0
  Downloading websocket_client-1.6.2-py3-none-any.whl (57 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 57.0/57.0 kB 1.4 MB/s eta 0:00:00
Collecting charset-normalizer<4,>=2
  Using cached charset_normalizer-3.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (199 kB)
Collecting idna<4,>=2.5
  Using cached idna-3.4-py3-none-any.whl (61 kB)
Collecting certifi>=2017.4.17
  Using cached certifi-2023.7.22-py3-none-any.whl (158 kB)
Installing collected packages: websocket-client, urllib3, packaging, idna, charset-normalizer, certifi, requests, docker
Successfully installed certifi-2023.7.22 charset-normalizer-3.2.0 docker-6.1.3 idna-3.4 packaging-23.1 requests-2.31.0 urllib3-2.0.4 websocket-client-1.6.2

[notice] A new release of pip available: 22.3.1 -> 23.2.1
[notice] To update, run: pip install --upgrade pip
(penv) [tavar@Nexus ModelToProduction]$ pip install --upgrade pip
Requirement already satisfied: pip in ./penv/lib/python3.11/site-packages (22.3.1)
Collecting pip
  Using cached pip-23.2.1-py3-none-any.whl (2.1 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 22.3.1
    Uninstalling pip-22.3.1:
      Successfully uninstalled pip-22.3.1
Successfully installed pip-23.2.1
(penv) [tavar@Nexus ModelToProduction]$ pip install docker
Requirement already satisfied: docker in ./penv/lib/python3.11/site-packages (6.1.3)
Requirement already satisfied: packaging>=14.0 in ./penv/lib/python3.11/site-packages (from docker) (23.1)
Requirement already satisfied: requests>=2.26.0 in ./penv/lib/python3.11/site-packages (from docker) (2.31.0)
Requirement already satisfied: urllib3>=1.26.0 in ./penv/lib/python3.11/site-packages (from docker) (2.0.4)
Requirement already satisfied: websocket-client>=0.32.0 in ./penv/lib/python3.11/site-packages (from docker) (1.6.2)
Requirement already satisfied: charset-normalizer<4,>=2 in ./penv/lib/python3.11/site-packages (from requests>=2.26.0->docker) (3.2.0)
Requirement already satisfied: idna<4,>=2.5 in ./penv/lib/python3.11/site-packages (from requests>=2.26.0->docker) (3.4)
Requirement already satisfied: certifi>=2017.4.17 in ./penv/lib/python3.11/site-packages (from requests>=2.26.0->docker) (2023.7.22)
(penv) [tavar@Nexus ModelToProduction]$ docker build --no-cache -t modeltoproduction .
DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
            Install the buildx component to build images with BuildKit:
            https://docs.docker.com/go/buildx/

Sending build context to Docker daemon  133.5MB
Step 1/8 : FROM python:3.10
 ---> 8c24eef72f16
Step 2/8 : WORKDIR /ModelToProduction
 ---> Running in e89653516f1b
Removing intermediate container e89653516f1b
 ---> 3494b56cbf34
Step 3/8 : COPY pyproject.toml poetry.lock* ./
 ---> 8c1116d05eb4
Step 4/8 : RUN pip install poetry
 ---> Running in 41dc2c8f3c36
Collecting poetry
  Downloading poetry-1.6.1-py3-none-any.whl (232 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 232.8/232.8 kB 4.3 MB/s eta 0:00:00
Collecting packaging>=20.4
  Downloading packaging-23.1-py3-none-any.whl (48 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 48.9/48.9 kB 8.1 MB/s eta 0:00:00
Collecting build<0.11.0,>=0.10.0
  Downloading build-0.10.0-py3-none-any.whl (17 kB)
Collecting pexpect<5.0.0,>=4.7.0
  Downloading pexpect-4.8.0-py2.py3-none-any.whl (59 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 59.0/59.0 kB 9.4 MB/s eta 0:00:00
Collecting requests<3.0,>=2.26
  Downloading requests-2.31.0-py3-none-any.whl (62 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.6/62.6 kB 8.9 MB/s eta 0:00:00
Collecting pyproject-hooks<2.0.0,>=1.0.0
  Downloading pyproject_hooks-1.0.0-py3-none-any.whl (9.3 kB)
Collecting tomli<3.0.0,>=2.0.1
  Downloading tomli-2.0.1-py3-none-any.whl (12 kB)
Collecting shellingham<2.0,>=1.5
  Downloading shellingham-1.5.3-py2.py3-none-any.whl (9.7 kB)
Collecting tomlkit<1.0.0,>=0.11.4
  Downloading tomlkit-0.12.1-py3-none-any.whl (37 kB)
Collecting keyring<25.0.0,>=24.0.0
  Downloading keyring-24.2.0-py3-none-any.whl (37 kB)
Collecting cleo<3.0.0,>=2.0.0
  Downloading cleo-2.0.1-py3-none-any.whl (77 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 77.3/77.3 kB 9.5 MB/s eta 0:00:00
Collecting cachecontrol[filecache]<0.14.0,>=0.13.0
  Downloading cachecontrol-0.13.1-py3-none-any.whl (22 kB)
Collecting requests-toolbelt<2,>=0.9.1
  Downloading requests_toolbelt-1.0.0-py2.py3-none-any.whl (54 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 54.5/54.5 kB 9.0 MB/s eta 0:00:00
Collecting poetry-plugin-export<2.0.0,>=1.5.0
  Downloading poetry_plugin_export-1.5.0-py3-none-any.whl (10 kB)
Collecting jsonschema<4.18.0,>=4.10.0
  Downloading jsonschema-4.17.3-py3-none-any.whl (90 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 90.4/90.4 kB 1.6 MB/s eta 0:00:00
Collecting trove-classifiers>=2022.5.19
  Downloading trove_classifiers-2023.8.7-py3-none-any.whl (13 kB)
Collecting installer<0.8.0,>=0.7.0
  Downloading installer-0.7.0-py3-none-any.whl (453 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 453.8/453.8 kB 9.7 MB/s eta 0:00:00
Collecting dulwich<0.22.0,>=0.21.2
  Downloading dulwich-0.21.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (512 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 512.2/512.2 kB 9.9 MB/s eta 0:00:00
Collecting pkginfo<2.0.0,>=1.9.4
  Downloading pkginfo-1.9.6-py3-none-any.whl (30 kB)
Collecting crashtest<0.5.0,>=0.4.1
  Downloading crashtest-0.4.1-py3-none-any.whl (7.6 kB)
Collecting poetry-core==1.7.0
  Downloading poetry_core-1.7.0-py3-none-any.whl (426 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 426.4/426.4 kB 9.7 MB/s eta 0:00:00
Collecting virtualenv<21.0.0,>=20.22.0
  Downloading virtualenv-20.24.4-py3-none-any.whl (3.7 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.7/3.7 MB 9.6 MB/s eta 0:00:00
Collecting platformdirs<4.0.0,>=3.0.0
  Downloading platformdirs-3.10.0-py3-none-any.whl (17 kB)
Collecting msgpack>=0.5.2
  Downloading msgpack-1.0.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (316 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 316.8/316.8 kB 10.2 MB/s eta 0:00:00
Collecting filelock>=3.8.0
  Downloading filelock-3.12.3-py3-none-any.whl (11 kB)
Collecting rapidfuzz<3.0.0,>=2.2.0
  Downloading rapidfuzz-2.15.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.0 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.0/3.0 MB 11.2 MB/s eta 0:00:00
Collecting urllib3>=1.25
  Downloading urllib3-2.0.4-py3-none-any.whl (123 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 123.9/123.9 kB 9.9 MB/s eta 0:00:00
Collecting attrs>=17.4.0
  Downloading attrs-23.1.0-py3-none-any.whl (61 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.2/61.2 kB 8.8 MB/s eta 0:00:00
Collecting pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0
  Downloading pyrsistent-0.19.3-py3-none-any.whl (57 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 57.5/57.5 kB 8.7 MB/s eta 0:00:00
Collecting jeepney>=0.4.2
  Downloading jeepney-0.8.0-py3-none-any.whl (48 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 48.4/48.4 kB 7.7 MB/s eta 0:00:00
Collecting importlib-metadata>=4.11.4
  Downloading importlib_metadata-6.8.0-py3-none-any.whl (22 kB)
Collecting jaraco.classes
  Downloading jaraco.classes-3.3.0-py3-none-any.whl (5.9 kB)
Collecting SecretStorage>=3.2
  Downloading SecretStorage-3.3.3-py3-none-any.whl (15 kB)
Collecting ptyprocess>=0.5
  Downloading ptyprocess-0.7.0-py2.py3-none-any.whl (13 kB)
Collecting idna<4,>=2.5
  Downloading idna-3.4-py3-none-any.whl (61 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.5/61.5 kB 8.8 MB/s eta 0:00:00
Collecting charset-normalizer<4,>=2
  Downloading charset_normalizer-3.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (201 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 201.8/201.8 kB 10.5 MB/s eta 0:00:00
Collecting certifi>=2017.4.17
  Downloading certifi-2023.7.22-py3-none-any.whl (158 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 158.3/158.3 kB 10.0 MB/s eta 0:00:00
Collecting distlib<1,>=0.3.7
  Downloading distlib-0.3.7-py2.py3-none-any.whl (468 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 468.9/468.9 kB 11.1 MB/s eta 0:00:00
Collecting typing-extensions>=4.7.1
  Downloading typing_extensions-4.7.1-py3-none-any.whl (33 kB)
Collecting zipp>=0.5
  Downloading zipp-3.16.2-py3-none-any.whl (7.2 kB)
Collecting cryptography>=2.0
  Downloading cryptography-41.0.3-cp37-abi3-manylinux_2_28_x86_64.whl (4.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.3/4.3 MB 11.3 MB/s eta 0:00:00
Collecting more-itertools
  Downloading more_itertools-10.1.0-py3-none-any.whl (55 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 55.8/55.8 kB 8.2 MB/s eta 0:00:00
Collecting cffi>=1.12
  Downloading cffi-1.15.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (441 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 441.8/441.8 kB 10.4 MB/s eta 0:00:00
Collecting pycparser
  Downloading pycparser-2.21-py2.py3-none-any.whl (118 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 118.7/118.7 kB 8.7 MB/s eta 0:00:00
Installing collected packages: trove-classifiers, ptyprocess, msgpack, distlib, zipp, urllib3, typing-extensions, tomlkit, tomli, shellingham, rapidfuzz, pyrsistent, pycparser, poetry-core, platformdirs, pkginfo, pexpect, packaging, more-itertools, jeepney, installer, idna, crashtest, charset-normalizer, certifi, attrs, requests, pyproject-hooks, jsonschema, jaraco.classes, importlib-metadata, filelock, dulwich, cleo, cffi, virtualenv, requests-toolbelt, cryptography, cachecontrol, build, SecretStorage, keyring, poetry-plugin-export, poetry
Successfully installed SecretStorage-3.3.3 attrs-23.1.0 build-0.10.0 cachecontrol-0.13.1 certifi-2023.7.22 cffi-1.15.1 charset-normalizer-3.2.0 cleo-2.0.1 crashtest-0.4.1 cryptography-41.0.3 distlib-0.3.7 dulwich-0.21.6 filelock-3.12.3 idna-3.4 importlib-metadata-6.8.0 installer-0.7.0 jaraco.classes-3.3.0 jeepney-0.8.0 jsonschema-4.17.3 keyring-24.2.0 more-itertools-10.1.0 msgpack-1.0.5 packaging-23.1 pexpect-4.8.0 pkginfo-1.9.6 platformdirs-3.10.0 poetry-1.6.1 poetry-core-1.7.0 poetry-plugin-export-1.5.0 ptyprocess-0.7.0 pycparser-2.21 pyproject-hooks-1.0.0 pyrsistent-0.19.3 rapidfuzz-2.15.1 requests-2.31.0 requests-toolbelt-1.0.0 shellingham-1.5.3 tomli-2.0.1 tomlkit-0.12.1 trove-classifiers-2023.8.7 typing-extensions-4.7.1 urllib3-2.0.4 virtualenv-20.24.4 zipp-3.16.2
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

[notice] A new release of pip is available: 23.0.1 -> 23.2.1
[notice] To update, run: pip install --upgrade pip
Removing intermediate container 41dc2c8f3c36
 ---> 52f27da2ff15
Step 5/8 : RUN poetry install
 ---> Running in f26952c1321b
Creating virtualenv modeltoproduction-ILSlifV8-py3.10 in /root/.cache/pypoetry/virtualenvs
Installing dependencies from lock file

Package operations: 113 installs, 0 updates, 0 removals

  • Installing attrs (23.1.0)
  • Installing rpds-py (0.9.2)
  • Installing referencing (0.30.2)
  • Installing six (1.16.0)
  • Installing jsonschema-specifications (2023.7.1)
  • Installing platformdirs (3.10.0)
  • Installing python-dateutil (2.8.2)
  • Installing traitlets (5.9.0)
  • Installing arrow (1.2.3)
  • Installing fastjsonschema (2.18.0)
  • Installing jsonschema (4.19.0)
  • Installing jupyter-core (5.3.1)
  • Installing pycparser (2.21)
  • Installing pyzmq (25.1.1)
  • Installing tornado (6.3.3)
  • Installing cffi (1.15.1)
  • Installing fqdn (1.5.1)
  • Installing idna (3.4)
  • Installing jsonpointer (2.4)
  • Installing markupsafe (2.1.3)
  • Installing isoduration (20.11.0)
  • Installing rfc3339-validator (0.1.4)
  • Installing jupyter-client (8.3.0)
  • Installing nbformat (5.9.2)
  • Installing rfc3986-validator (0.1.1)
  • Installing ptyprocess (0.7.0)
  • Installing soupsieve (2.4.1)
  • Installing webcolors (1.13)
  • Installing uri-template (1.3.0)
  • Installing webencodings (0.5.1)
Connection pool is full, discarding connection: pypi.org. Connection pool size: 10
Connection pool is full, discarding connection: pypi.org. Connection pool size: 10
Connection pool is full, discarding connection: pypi.org. Connection pool size: 10
Connection pool is full, discarding connection: pypi.org. Connection pool size: 10
Connection pool is full, discarding connection: pypi.org. Connection pool size: 10
  • Installing argon2-cffi-bindings (21.2.0)
  • Installing asttokens (2.2.1)
  • Installing beautifulsoup4 (4.12.2)
  • Installing bleach (6.0.0)
  • Installing defusedxml (0.7.1)
  • Installing exceptiongroup (1.1.3)
  • Installing executing (1.2.0)
  • Installing jinja2 (3.1.2)
  • Installing jupyterlab-pygments (0.2.2)
  • Installing mistune (3.0.1)
  • Installing nbclient (0.8.0)
  • Installing packaging (23.1)
  • Installing pandocfilters (1.5.0)
  • Installing parso (0.8.3)
  • Installing pure-eval (0.2.2)
  • Installing pygments (2.16.1)
  • Installing python-json-logger (2.0.7)
  • Installing pyyaml (6.0.1)
  • Installing sniffio (1.3.0)
  • Installing terminado (0.17.1)
  • Installing tinycss2 (1.2.1)
Connection pool is full, discarding connection: pypi.org. Connection pool size: 10
Connection pool is full, discarding connection: pypi.org. Connection pool size: 10
Connection pool is full, discarding connection: pypi.org. Connection pool size: 10
Connection pool is full, discarding connection: pypi.org. Connection pool size: 10
Connection pool is full, discarding connection: pypi.org. Connection pool size: 10
  • Installing wcwidth (0.2.6)
Connection pool is full, discarding connection: pypi.org. Connection pool size: 10
  • Installing anyio (3.7.1)
  • Installing argon2-cffi (23.1.0)
  • Installing backcall (0.2.0)
  • Installing certifi (2023.7.22)
  • Installing charset-normalizer (3.2.0)
  • Installing decorator (5.1.1)
  • Installing jedi (0.19.0)
  • Installing jupyter-events (0.7.0)
  • Installing jupyter-server-terminals (0.4.4)
  • Installing matplotlib-inline (0.1.6)
  • Installing nbconvert (7.7.4)
  • Installing overrides (7.4.0)
  • Installing pexpect (4.8.0)
  • Installing pickleshare (0.7.5)
  • Installing prometheus-client (0.17.1)
  • Installing prompt-toolkit (3.0.39)
  • Installing send2trash (1.8.2)
  • Installing stack-data (0.6.2)
  • Installing urllib3 (2.0.4)
  • Installing websocket-client (1.6.2)
Connection pool is full, discarding connection: pypi.org. Connection pool size: 10
Connection pool is full, discarding connection: pypi.org. Connection pool size: 10
Connection pool is full, discarding connection: pypi.org. Connection pool size: 10
Connection pool is full, discarding connection: pypi.org. Connection pool size: 10
Connection pool is full, discarding connection: pypi.org. Connection pool size: 10
Connection pool is full, discarding connection: pypi.org. Connection pool size: 10
  • Installing babel (2.12.1)
  • Installing comm (0.1.4)
  • Installing debugpy (1.6.7.post1)
  • Installing ipython (8.14.0)
  • Installing json5 (0.9.14)
  • Installing jupyter-server (2.7.2)
  • Installing nest-asyncio (1.5.7)
  • Installing psutil (5.9.5)
  • Installing requests (2.31.0)
  • Installing typing-extensions (4.7.1)
  • Installing async-lru (2.0.4)
  • Installing ipykernel (6.25.1)
  • Installing jupyter-lsp (2.2.0)
  • Installing notebook-shim (0.2.3)
  • Installing tomli (2.0.1)
  • Installing jupyterlab-server (2.24.0)
  • Installing ipython-genutils (0.2.0)
  • Installing jupyterlab (4.0.5)
  • Installing jupyterlab-widgets (3.0.8)
  • Installing numpy (1.25.2)
  • Installing qtpy (2.3.1)
  • Installing widgetsnbextension (4.0.8)
  • Installing blinker (1.6.2)
  • Installing click (8.1.7)
  • Installing ipywidgets (8.1.0)
  • Installing itsdangerous (2.1.2)
  • Installing joblib (1.3.2)
  • Installing jupyter-console (6.6.3)
  • Installing mypy-extensions (1.0.0)
  • Installing notebook (7.0.2)
  • Installing pastel (0.2.1)
  • Installing pathspec (0.11.2)
  • Installing scipy (1.11.2)
  • Installing werkzeug (2.3.7)
  • Installing qtconsole (5.4.3)
  • Installing threadpoolctl (3.2.0)
Connection pool is full, discarding connection: pypi.org. Connection pool size: 10
Connection pool is full, discarding connection: pypi.org. Connection pool size: 10
Connection pool is full, discarding connection: pypi.org. Connection pool size: 10
Connection pool is full, discarding connection: pypi.org. Connection pool size: 10
  • Installing black (23.7.0)
  • Installing flask (2.3.3)
  • Installing jupyter (1.0.0)
  • Installing poethepoet (0.22.0)
  • Installing scikit-learn (1.3.0)
Removing intermediate container f26952c1321b
 ---> 97891cddf568
Step 6/8 : COPY . /ModelToProduction
 ---> f5c23b1590bd
Step 7/8 : EXPOSE 5000
 ---> Running in 60ffc2883efd
Removing intermediate container 60ffc2883efd
 ---> bd140e612197
Step 8/8 : CMD ["python", "server/main.py"]
 ---> Running in 34ac55ac8fd4
Removing intermediate container 34ac55ac8fd4
 ---> f3356d86b527
Successfully built f3356d86b527
Successfully tagged modeltoproduction:latest

But it does not find flask and, in fact, don’t even install poetry:

(penv) [tavar@Nexus ModelToProduction]$ docker run -p 5000:5000 modeltoproduction
Traceback (most recent call last):
  File "/ModelToProduction/server/main.py", line 2, in <module>
    from flask import Flask, request
ModuleNotFoundError: No module named 'flask'

Could anyone help me where the mistake is?

Best,
Tavar

A very primitive approach to try to solve this:

Add an endless loop script and execute that as final Dockerfile statement.

Use docker exec -it <cid> sh to get into a container shell. Try to run your script there, check the filesystem, where files may have ended up.

Thank you for your answer. This looks like a workaround. For a course I have to get it run in an elegant way… isn’t there something wrong with my docker file?

It’s not a workaround, it’s a way to dive into the container, checking everything is installed correctly, in the right locations, then try to start your app manually.

Then work backwards from a running app to get the Dockerfile fixed. Often it’s a path problem.