Can I get answer to this problem related to build ...
# ask-community
z
Can I get answer to this problem related to build docker image please? I have put it in Stackoverflow, hoping to help with the others to search. When using docker as storage, in the call as below:
Copy code
prefect register --project yourproject -p yourflow.py
It seems that perfect creates a
tmp{randomNumber}
folder and puts healthcheck.py and a Dockerfile, which participate the docker build. But I accidentally deleted the
tmp
folder, even after I recovered it, it still throws the following error. What happened was that Prefect expected a
tmp
folder with a new random_number as the suffix. How can I recover from it? https://stackoverflow.com/questions/70198040/error-in-prefect-when-build-docker-image-what-triggers-prefect-to-create-the-tm
a
As a quick fix, you could disable the health check:
Copy code
from prefect.storage import Docker

Docker(ignore_healthchecks=True)
In general, it looks like you run the registration itself in a Docker container, and this is why the health checks are failing. The registration step is building an image and right now you are building Docker images from a Docker container rather than from a local process. You could in theory solve it with docker.sock, but there is a much easier way. You can create a virtual environment for the registration process. Within that environment, you can register all flows at once using CLI rather than doing that with a custom code:
Copy code
prefect register --project yourproject -p /path/to/flows/dir/
All flows in the
dir
directory, will then be registered one by one, and for each of them, Prefect will build its own Docker image.
z
I added ignore_healthchecks=True, It still throws the same error. It tried to copy files from the tmp folder (
Step 10/10 : COPY ./tmpl5xqtl1e/healthcheck.py /opt/prefect/healthcheck.py
), while I have deleted that previoud tmp folder and seems this triggers Prefect to create a random number to append after “tmp” to use as the folder name. I call
register
from Mac terminal in the virtual env of the Python project. There is no “register” called in the flow.py file. I can’t figure out how I build the image inside of the container. Thus looking for some clue. This is the structure of my flow.py file
Copy code
with Flow("My First Flow") as flow:

# steps of the flow

flow.storage = Docker(registry_url="<http://de.icr.io/cogssm-dev/|de.icr.io/cogssm-dev/>", image_name="train_flow", dockerfile="./Dockerfile", ignore_healthchecks=True)
flow.storage.build()
This is my .dockerfile
Copy code
FROM prefecthq/prefect:0.7.1-python3.7

WORKDIR /app

ADD . .

RUN pip install --no-cache-dir -r requirements.txt
Then in the CLI, I do: prefect register --project yourproject -p yourflow.py
a
@Zheng Xie there are a couple of issues here: #1 Remove this line from the flow definition - the reason is that otherwise Prefect will try to build the storage twice. The “prefect register” CLI command automatically builds storage so this line is not needed:
Copy code
flow.storage.build()
#2 Where did you get this line from? Could it be that it’s from some old tutorial? Prefect is by now in version 0.15.9 and this image is using a very old version.
Copy code
FROM prefecthq/prefect:0.7.1-python3.7
So it would be better to use e.g.:
Copy code
FROM prefecthq/prefect:0.15.9-python3.9
Then, you could use:
Copy code
prefect register --project yourproject -p yourflow.py
Unless you really need that specific Prefect version (0.7.1) for some reason?
z
I just wanted python3.7 because my other methods were created in 3.7. Guess I can do:
Copy code
FROM prefecthq/prefect:0.15.9-python3.7
would it be ok for the latest Prefect with python 3.7?
a
yup, that’s 100% correct
z
Hi Anna, I have done the above, but still get the same error. attach the print out of the “register” command.
It was all working, and passed the 11 steps in the build, until I deleted the “tmp” folder. Prefect creates this tmp folder with a Dockerfile and the healthcheck.py in it. My Dockerfile has only 4 steps, the rest of the steps are from the Dockerfile in the tmp folder. How even I recover the tmp folder, it throws error, because the tmp folder it looks for has a new random number appended every time I ran the register command. Is it to do some clean out? I have tried to delete the “tmp” and the “tokens” folders that were created by Prefect
a
First, do you have this module installed in your “venv”? looks like its missing in your registration env
Copy code
UserWarning: Could not import the lzma module.
Can you share your flow file and Dockerfile? you can share it via DM to keep it private. It looks like the COPY command failed in the build. What files are you trying to copy to the image? I know you meant tmp folder, but maybe you can make it more explicit in your Dockerfile and only COPY or ADD things that are relevant for your flow? In general, the Docker storage build typically fails when there is something in your flow that cannot be serialized with cloudpickle - can it be you use some database connection or HTTP client outside of a @task?
z
Thanks Anna, I only instructed 4 steps in my Dockerfile, which are the 1st 4 steps you can see in the print out. The rest of the 8 steps, including the failing step that does the copy of the tmp folder, are not from my Dockerfile. The tmp folder isn’t mine either. I think it is Prefect created it. In the tmp folder, it has a Docker file. Let me recover the tmp folder and post it here.
a
Thanks for sharing the file! I think you can remove all those lines from the Dockerfile:
Copy code
RUN pip show prefect || pip install git+<https://github.com/PrefectHQ/prefect.git@0.15.6#egg=prefect[all_orchestration_extras]>

RUN mkdir -p /opt/prefect/

COPY ./tmpctfg2vxw/healthcheck.py /opt/prefect/healthcheck.py

RUN python /opt/prefect/healthcheck.py '[]' '(3, 7)'
The Docker image already has all extras afaik, so no need to install it explicitly. The /opt/prefect will be created automatically too. And those healthchecks don’t need to be set in the Dockerfile. Btw, this Dockerfile still uses Prefect 0.7.1. Can you perhaps remove all the tmp files and try this Dockerfile? I included all your custom logic:
Copy code
FROM prefecthq/prefect:0.15.9-python3.7
RUN /usr/local/bin/python -m pip install --upgrade pip
WORKDIR /opt/prefect
COPY your_project_directory_with_only_relevant_files/ /opt/prefect/your_project_directory_with_only_relevant_files/
COPY requirements.txt .
RUN pip install -r requirements.txt
ENV PREFECT__USER_CONFIG_PATH='/opt/prefect/config.toml'
z
Hi Anna, thanks for all the effort you have spent. But I think there is a blind spot. My Dockerfile has only 4 steps:
Copy code
FROM prefecthq/prefect:0.15.6-python3.7

WORKDIR /app

ADD . .

RUN pip install --no-cache-dir -r requirements.txt
I don’t need any of the following 7 steps as seen in the output of the “register” command. Where these steps come from? The “tmp” folder in the zip file was not my files, I think Prefect created it. It used to work, i could build the image and upload the image to container registry, until I deleted the “tmp” folder.
Now without the “tmp” folder in my workspace, Prefect seem to get the 11 step Dockerfile from somewhere and assume there is a tmp folder to copy the healthcheck.py. I have only one Dockerfile in my workspace, which only has 4 steps
a
@Zheng Xie can you try building this image independently of Prefect? just using:
Copy code
docker build -t yourimage .
z
by using
Copy code
docker build -t yourimage .
There are only my 4 steps in the output. But when run prefect register --project yourproject -p yourflow.py there are 11 steps in the output.
I have tried to create a new project in Prefect Cloud… Now I am going to start a new workspace, just download the source code and try again
a
@Zheng Xie you could also follow this tutorial to debug Docker storage issues: https://docs.prefect.io/core/advanced_tutorials/local-debugging.html#locally-check-your-flow-s-docker-storage