Hi everyone, excited to get handy with Prefect. I'...
# ask-community
s
Hi everyone, excited to get handy with Prefect. I'm trying to run Prefect server and client from single docker, and I need your help in figuring out this. My docker-compose.yaml looks like this:
Copy code
services:
  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:
Copy code
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:
Copy code
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.
g
you need a container to run the prefect server start command, you'll also need a separate container to run your prefect db
s
Thanks for the quick reply, but what do you mean by prefect db, doesn't prefect take care of db itself. Do you have any guide or example code for the above, or can you/someone give a boilerplate code for the above?
g
i'm sorry i forgot to ask, are you hosting your own server? if you are using prefect cloud then prefect handles the db, but if you are self-hosting you need a docker container for that, see: https://orion-docs.prefect.io/2.10.0/concepts/database/
s
Yes, I'm hosting the server locally. Thanks for the help.