A refactored, dynamic template derived from the official Dagster “deploy with Docker Compose” example, designed for flexible configuration and simple deployment. More about Dagster services here.
This template follows the recommended Dagster Docker Compose architecture: a webserver, a daemon, and one or more code locations. Each pipeline run typically launches in a dedicated container for isolation and scalability.
Configuration options can be overridden via environment variables:
- Postgres connection:
SetDAGSTER_POSTGRES_USER,DAGSTER_POSTGRES_PASSWORD,DAGSTER_POSTGRES_PORTandDAGSTER_POSTGRES_DBon the webserver, daemon, and code location services for storage of runs, logs, and schedules. - Ports:
UseDAGSTER_WEBSERVER_PORTto expose the webserver (e.g., 3000) andDAGSTER_CODE_EXAMPLE_PORTfor each code location’s gRPC server; assign unique ports in yourdocker-compose.yamland.envfiles. - Code location identification:
Name variables for each code location following a pattern likeDAGSTER_CODE_<IDENTIFIER>_NAMEandDAGSTER_CODE_<IDENTIFIER>_PORT, where<IDENTIFIER>matches the folder underservices/orchestration/dagster/pipelines/<identifier>.
Follow this pattern to add another code location (code location):
- Clone example pipeline:
Copy theservices/orchestration/dagster/pipelines/examplefolder to a new directory, such asanalytics(services/orchestration/dagster/pipelines/analytics). - Configure environment variables:
Add environment variables in your.envor Compose config:DAGSTER_CODE_ANALYTICS_NAMEDAGSTER_CODE_ANALYTICS_PORTFollow the pattern:DAGSTER_CODE_<IDENTIFIER>_NAMEandDAGSTER_CODE_<IDENTIFIER>_PORT
- Update New Code Location service:
Duplicate thedagster_code_exampleservice in thedocker-compose.yaml, rename it (e.g.,dagster_code_analytics), and update its settings (image name, build context, environment, port matching your new directory and variables if needed). - Update Dagster's Webserver and Daemon services:
Update bothdocker-compose.yamlandDockerfile.dagsterfor your new code location:
- In
docker-compose.yaml: Add ARG variables for the build for the new code location - In
Dockerfile.dagster: Add ARG and ENV declarations after the existing example:
ARG DAGSTER_CODE_ANALYTICS_PORT
ARG DAGSTER_CODE_ANALYTICS_NAME
dagster_code_analytics:
build:
context: ./services/orchestration/dagster/pipelines
dockerfile: ./analytics/Dockerfile.code_space
args:
- DAGSTER_CODE_THIS_NAME=${DAGSTER_CODE_ANALYTICS_NAME}
- DAGSTER_CODE_THIS_PORT=${DAGSTER_CODE_ANALYTICS_PORT}
container_name: ${DAGSTER_CODE_ANALYTICS_NAME}
image: "${DAGSTER_CODE_ANALYTICS_NAME}_image"
restart: always
environment:
WAREHOUSE_POSTGRES_USER: ${DAGSTER_POSTGRES_USER}
WAREHOUSE_POSTGRES_PASSWORD: ${DAGSTER_POSTGRES_PASSWORD}
WAREHOUSE_POSTGRES_DB: ${DAGSTER_POSTGRES_DB}
WAREHOUSE_POSTGRES_PORT: ${DAGSTER_POSTGRES_PORT}
DAGSTER_CURRENT_IMAGE: "${DAGSTER_CODE_ANALYTICS_NAME}_image"
DAGSTER_CODE_THIS_PORT: ${DAGSTER_CODE_ANALYTICS_PORT}
DAGSTER_CODE_THIS_NAME: ${DAGSTER_CODE_ANALYTICS_NAME}
ports:
- ${DAGSTER_CODE_ANALYTICS_PORT}:${DAGSTER_CODE_ANALYTICS_PORT}
networks:
- ${PIPELINE_NETWORK_NAME}
# New code location
DAGSTER_CODE_ANALYTICS_NAME=analytics
DAGSTER_CODE_ANALYTICS_PORT=4001
# Global/shared variables
DAGSTER_POSTGRES_USER=postgres_user
DAGSTER_POSTGRES_PASSWORD=postgres_password
DAGSTER_POSTGRES_DB=postgres_db
- Docker and Docker Compose are installed locally or on the target host.
- Clone the repository.
git clone git@github.com:Luk-kar/dagster-docker-deploy-template.git
cd dagster-docker-deploy-template
- Rename the
.env.exampleto.env:
cp ".env.example" ".env"
- Review and adjust values in
.envand update code location entries indocker-compose.yamlas needed. - Build images:
docker compose build
This builds the Dagster webserver/daemon image and any user‑code images defined in the Compose file.
- Launch the stack:
docker compose up
This starts the webserver, daemon, backing services (e.g., Postgres), and code locations.
- Dynamic templating: Incorporates templating (e.g., Jinja) and scripts to generate configuration (
dagster.yamlandworkspace.yaml) and compose files more flexibly than a static example. - Template orientation: Structured as a reusable starting point rather than a single fixed configuration in the Dagster monorepo example directory.
- Same deployment model: Retains Dagster’s recommended Docker Compose topology (webserver, daemon, code locations, per‑run containers).
- Added volume mounts for hot-reloading during development
- Use secrets instead of the
.envfile when you set up in production. - Validate container startup by checking logs for the webserver and daemon services after docker compose up.
- Ensure DAGSTER_HOME is set within images that run Dagster processes and that dagster.yaml/workspace.yaml are available there.