Victor
03/08/2025, 12:55 AM2025-03-08T00:04:13.098361341Z 00:04:12.922 | INFO | prefect.flow_runs.runner - Reported flow run 'aa252e24-14c1-4492-8ddd-8a36cd0668fb' as crashed: Flow run process exited with non-zero status code 1.
2025-03-08T00:04:13.098365529Z 00:04:12.939 | INFO | prefect.flow_runs.runner - Loading flow to check for on_crashed hooks
2025-03-08T00:04:13.098369437Z 00:04:13.023 | INFO | Flow run 'eager-boobook' - > Running set_working_directory step...
2025-03-08T00:04:13.098373424Z 00:04:13.089 | ERROR | Flow run 'eager-boobook' - [Errno 2] No such file or directory: '/opt/prefect/projectname'
here is my Dockerfile:
FROM prefecthq/prefect:3.2.9-python3.11
RUN mkdir -p /opt/prefect/projectname
COPY . /opt/prefect/projectname/
WORKDIW /opt/prefect/projectname/
RUN pip install -r dt/pdf_reader/requirements.txt
here is the success deploy log:
✦ 10% ❯ prefect deploy --prefect-file ./dt/pdf_reader/prefect.yaml --name 'pdf-reader-docker-deploy'
? Does your Dockerfile have a line that copies the current working directory into your image? [y/n]: y
? What is the path to your flow code in your Dockerfile? (/opt/prefect/projectname):
Running deployment build steps...
> Running build_docker_image step...
Step 1/5 : FROM prefecthq/prefect:3.2.9-python3.11
Marvin
03/08/2025, 12:55 AMWORKDIR
directive. There is a typo in your Dockerfile: WORKDIW
should be WORKDIR
. This typo is causing the error [Errno 2] No such file or directory: '/opt/prefect/projectname'
because the working directory is not being set correctly.
Here's the corrected Dockerfile snippet:
Dockerfile
FROM prefecthq/prefect:3.2.9-python3.11
RUN mkdir -p /opt/prefect/projectname
COPY . /opt/prefect/projectname/
WORKDIR /opt/prefect/projectname/
RUN pip install -r dt/pdf_reader/requirements.txt
Additionally, here are some helpful links and notes that might be useful for your setup:
- Prefect Docker Infrastructure Example: This document provides guidance on setting up Docker infrastructure for Prefect.
- GitHub Issue on FileNotFoundError: A related issue discussing similar errors with Docker deployments.
Ensure your Dockerfile is correctly set up, and this should resolve the error. If issues persist, double-check the paths and permissions within your Docker image.Victor
03/08/2025, 12:57 AMFROM prefecthq/prefect:3.2.9-python3.11
COPY . /opt/prefect/projectname
WORKDIR /opt/prefect/projectname
pull section of yaml:
pull:
- prefect.deployments.steps.set_working_directory:
directory: './'
latest error:
> Running set_working_directory step...
01:52:56 AM
prefect.flow_runs
[Errno 2] No such file or directory: '/opt/prefect/projectname'
Marvin
03/08/2025, 12:57 AMset_working_directory
step is being configured and executed in your deployment. The directory: './'
setting in your prefect.yaml
might not be resolving to the intended path within the Docker container.
Here's what you should consider:
1. Directory Path in Docker: Ensure that the path you're setting in the set_working_directory
step matches the path where your files are actually located inside the Docker container. In your case, it should match /opt/prefect/projectname
.
2. Correcting the YAML: You might need to explicitly specify the directory path in your prefect.yaml
file to match the path inside the container. Update your pull
section like this:
yaml
pull:
- prefect.deployments.steps.set_working_directory:
directory: '/opt/prefect/projectname'
3. Documentation Reference: For more details on managing deployments and the pull
section, refer to the Prefect YAML Documentation.
By ensuring the paths align correctly, you should be able to resolve the No such file or directory
error. If further issues arise, double-check the deployment process and ensure that the Docker image is built correctly with the necessary files.Victor
03/08/2025, 1:11 AMUnexpected exception encountered when trying to load flow
Traceback (most recent call last):
File "<frozen importlib._bootstrap_external>", line 995, in exec_module
File "<frozen importlib._bootstrap_external>", line 1132, in get_code
File "<frozen importlib._bootstrap_external>", line 1190, in get_data
FileNotFoundError: [Errno 2] No such file or directory: '/opt/prefect/dt/pdf_reader/main.py'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/prefect/engine.py", line 112, in <module>
flow: "Flow[..., Any]" = load_flow(flow_run)
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/prefect/flow_engine.py", line 140, in load_flow
flow = run_coro_as_sync(
^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/prefect/utilities/asyncutils.py", line 207, in run_coro_as_sync
return call.result()
^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/prefect/_internal/concurrency/calls.py", line 329, in result
return self.future.result(timeout=timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/prefect/_internal/concurrency/calls.py", line 192, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
raise self._exception
File "/usr/local/lib/python3.12/site-packages/prefect/_internal/concurrency/calls.py", line 402, in _run_async
result = await coro
^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/prefect/utilities/asyncutils.py", line 188, in coroutine_wrapper
return await task
^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/prefect/client/utilities.py", line 69, in wrapper
return await func(client, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/prefect/flows.py", line 2380, in load_flow_from_flow_run
flow = await run_sync_in_worker_thread(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/prefect/utilities/asyncutils.py", line 233, in run_sync_in_worker_thread
result = await anyio.to_thread.run_sync(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/anyio/to_thread.py", line 56, in run_sync
return await get_async_backend().run_sync_in_worker_thread(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 2461, in run_sync_in_worker_thread
return await future
^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 962, in run
result = context.run(func, *args)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/prefect/utilities/asyncutils.py", line 243, in call_with_mark
return call()
^^^^^^
File "/usr/local/lib/python3.12/site-packages/prefect/flows.py", line 2059, in load_flow_from_entrypoint
flow: Flow[P, Any] = import_object(entrypoint) # pyright: ignore[reportRedeclaration]
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/prefect/utilities/importtools.py", line 156, in import_object
module = load_script_as_module(script_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/prefect/utilities/importtools.py", line 121, in load_script_as_module
raise ScriptError(user_exc=exc, path=path) from exc
prefect.exceptions.ScriptError: Script at 'dt/pdf_reader/main.py' encountered an exception: FileNotFoundError(2, 'No such file or directory')
Marvin
03/08/2025, 1:11 AMVictor
03/08/2025, 1:12 AMUnexpected exception encountered when trying to load flow
Traceback (most recent call last):
File "<frozen importlib._bootstrap_external>", line 995, in exec_module
File "<frozen importlib._bootstrap_external>", line 1132, in get_code
File "<frozen importlib._bootstrap_external>", line 1190, in get_data
FileNotFoundError: [Errno 2] No such file or directory: '/opt/prefect/dt/pdf_reader/main.py'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/prefect/engine.py", line 112, in <module>
flow: "Flow[..., Any]" = load_flow(flow_run)
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/prefect/flow_engine.py", line 140, in load_flow
flow = run_coro_as_sync(
^^^^^^^^^^^^^^^^^
.....
.....
^^^^^^
File "/usr/local/lib/python3.12/site-packages/prefect/flows.py", line 2059, in load_flow_from_entrypoint
flow: Flow[P, Any] = import_object(entrypoint) # pyright: ignore[reportRedeclaration]
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/prefect/utilities/importtools.py", line 156, in import_object
module = load_script_as_module(script_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/prefect/utilities/importtools.py", line 121, in load_script_as_module
raise ScriptError(user_exc=exc, path=path) from exc
prefect.exceptions.ScriptError: Script at 'dt/pdf_reader/main.py' encountered an exception: FileNotFoundError(2, 'No such file or directory')
Marvin
03/08/2025, 1:12 AMdt/pdf_reader/main.py
, is not found within the Docker container. This is often due to discrepancies in how files are copied into the Docker image or how paths are referenced.
Here's what you can do to troubleshoot and resolve this issue:
1. Verify Dockerfile COPY Command: Ensure that the COPY
command in your Dockerfile correctly copies the necessary files and directories into the Docker image. Double-check the relative path from your Docker build context (usually the directory containing the Dockerfile) to the file dt/pdf_reader/main.py
.
2. Update Dockerfile: Make sure your Dockerfile includes all necessary files. If dt/pdf_reader/main.py
is not at the root of your build context, adjust your COPY
command accordingly. For example:
dockerfile
FROM prefecthq/prefect:3.2.9-python3.11
COPY . /opt/prefect/projectname
WORKDIR /opt/prefect/projectname
Ensure that the directory structure in your Docker image matches where main.py
is expected to be located.
3. Check Entrypoint in prefect.yaml: Ensure that the entrypoint in your prefect.yaml
is correctly specified. For example, if your main.py
is located under dt/pdf_reader
, the entrypoint should reflect this path accurately.
4. Documentation Reference: For more detailed guidance on Docker deployments, you can refer to the Prefect Docker Infrastructure Example.
By ensuring the file paths and Dockerfile configurations are correct, you should be able to resolve the FileNotFoundError
. If issues persist, consider building the Docker image manually and inspecting it to verify the file structure.