It seems like `prefect server` is trying to run `d...
# ask-community
m
It seems like
prefect server
is trying to run
docker-compose
inside its own container and not finding the binary?
Copy code
prefect-server-1  | FileNotFoundError: [Errno 2] No such file or directory: 'docker-compose': 'docker-compose'
This is the compose file I'm using:
Copy code
---
version: "3.7"

services:
  prefect-server:
    image: prefecthq/prefect
    restart: always
    command: prefect server start
    environment:
      - PREFECT_UI_URL=<http://127.0.0.1:4900/api>
      - PREFECT_API_URL=<http://127.0.0.1:4900/api>
      - PREFECT_SERVER_API_HOST=0.0.0.0
    ports:
      - 4900:4900
Is there any documentation available for running the latest version of prefect in docker-compose?
a
Try this one. Make sure you set the environment vars:
Copy code
services:
  db:
    container_name: db
    image: postgres:${POSTGRES_VERSION}
    restart: unless-stopped
    environment:
      - POSTGRES_USER=${PREFECT_POSTGRES_USER}
      - POSTGRES_PASSWORD=${PREFECT_POSTGRES_PASSWORD}
      - POSTGRES_DB=prefect
    volumes: 
      - db:/var/lib/postgresql/data
    networks:
      - prefect

  prefect:
    container_name: prefect
    image: prefecthq/prefect:${PREFECT_IMAGE}
    restart: unless-stopped
    volumes:
      - prefect:/root/.prefect
    environment:
      - PREFECT_API_URL=<http://127.0.0.1:4200/api>
      - PREFECT_SERVER_API_HOST=0.0.0.0
      - PREFECT_API_DATABASE_CONNECTION_URL=postgresql+asyncpg://${PREFECT_POSTGRES_USER}:${PREFECT_POSTGRES_PASSWORD}@db:5432/prefect
    command: prefect server start
    ports:
      - 4200:4200
    networks:
      - prefect
    depends_on: 
      - db

volumes:
  prefect:
  db:
networks:
  prefect:
m
Apparently my issue is related to the
latest
tag on Docker hub being more than a year old. This is probably a bit confusing for most users.
b
When trying to run Prefect Server (specifically running
prefect server start
) in an environment with existing containers, you want to use a
docker-along-side-docker
approach. Basically in your compose file you want to bind mount the host's docker socket into the container that run's the
prefect server start
command. Something like
Copy code
services:
  prefect-server:
    # ...
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
This will allow your
prefect-server
container to create sibling containers. Without the bind, the
prefect-server
would create child containers inside of itself (called docker-in-docker). This works, but is actively discouraged by the person who implemented the functionality to allow it. Using the bind mount to the docker socket essentially turns your
prefect-server
into an orchestration or command & control container, similar to how Kubernetes operates. The
prefect-server
container needs to have
docker-compose
installed and accessible, but does not need to have
docker
installed. The only other change needed is to adjust the host name of the Prefect API server. Since everything is running inside Docker and over a bridge network, container's cannot refer to other containers using
localhost
Instead they must use the name of the service. The command
prefect server start
will create several services, one of them named
appollo
, That is the API server. To get the other services to use it, you just need to create the following configuration file:
Copy code
backend = "server"

[server]
# "apollo" is the name of the prefect/docker-compose service that runs the Prefect server. Any container that uses this
# config file must be on the same docker network as the Prefect server (default: prefect-server)
host = "<http://apollo>"
port = "4200"