Shahid Khan
01/08/2025, 10:56 AMservices:
prefect-worker:
build:
context: .
dockerfile: Dockerfile
container_name: prefect_worker_alert
environment:
PREFECT_API_URL: "<http://127.0.0.1:4200/api>"
restart: unless-stopped
My Dockerfile looks like this:
FROM python:3.9-slim
# Set timezone to Asia/Kolkata
RUN apt-get update && \
apt-get install -y --no-install-recommends \
tzdata && \
ln -fs /usr/share/zoneinfo/Asia/Kolkata /etc/localtime && \
dpkg-reconfigure -f noninteractive tzdata && \
apt-get clean && rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /app
# Copy application files to container
COPY . /app/
# Install Python dependencies
RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
pip install --no-cache-dir -r requirements.txt
# Prefect setup
RUN prefect work-pool create --type process alerts || true && \
yes n | prefect deploy --all
# Command to start Prefect worker
CMD ["prefect", "worker", "start", "-p", "alerts", "--limit", "15"]
My prefect.yaml looks like this:
deployments:
- name: Energy Alerts
entrypoint: mainfile.py:flow_method
schedule:
interval: 300
parameters: {}
work_pool:
name: alerts
work_queue_name: null
job_variables: {}
Now, how can I start my prefect server from this same docker, and access my deployments and runs from the Prefect UI directly.
Requirements.txt has prefect==2.20.3
PS: I've achieved this by running prefect server start
in my machine, but I don't want to run any command, and want all this to be taken care by Docker deployment.
Thanks for the help, well. in advance.Guilins
01/08/2025, 12:22 PMShahid Khan
01/08/2025, 1:16 PMGuilins
01/08/2025, 3:09 PMShahid Khan
01/09/2025, 8:24 PM