dbt docs serve

Galaxy Glossary

What does dbt docs serve do and how do you use it?

dbt docs serve starts a local web server that renders interactive documentation for your compiled dbt project.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.

Description

Table of Contents

What Is dbt docs serve?

dbt docs serve is a CLI sub-command that spins up a lightweight local web server to display the auto-generated documentation for your compiled dbt project. The server bundles model lineage graphs, column metadata, and test status into an interactive UI that opens in your browser.

Why Use dbt docs serve Instead of dbt docs generate?

dbt docs generate creates static HTML files, but it does not serve them. dbt docs serve adds a transient HTTP server so you can explore docs instantly without moving files to a host. This speeds up review cycles and encourages frequent documentation checks during development.

How Do I Start dbt docs serve?

Run the following from your project root after compiling your models:

dbt docs serve --port 8081 --profiles-dir ~/.dbt

The command builds docs (if they don’t exist) and serves them at https://localhost:8081 by default, then opens your default browser.

Can I Change the Host or Port?

Yes—use --port and --host flags. Example: dbt docs serve --host 0.0.0.0 --port 9000. This is useful inside Docker or remote development environments.

What Happens Under the Hood?

The command first calls dbt docs generate to compile manifest.json and HTML assets in target/. It then launches a simple Flask app that reads those assets and exposes endpoints for search, lineage, and static files.

How Do I Stop the Server?

Press Ctrl+C in the terminal where dbt docs serve is running. The process ends, freeing the port and shutting down the Flask app.

Where Does dbt docs serve Fit in CI/CD?

Many teams add dbt docs generate in CI to publish static docs to S3 or Netlify. Use dbt docs serve only for local exploration or ephemeral review apps because it stores nothing persistently.

How Can I Access dbt docs inside Galaxy?

Galaxy users can map the running dbt docs port to the Galaxy desktop app via Open URL. This lets developers jump from a SQL query to model lineage in one click, enabling a seamless debugging loop.

Best Practices for dbt docs serve

Compile models first to avoid long startup times. Allocate a consistent port across projects to simplify browser bookmarks. Version-lock dbt to keep generated docs schemas compatible with your project.

Common Pitfalls and Fixes

Port conflicts—choose an unused port. Missing manifest—run dbt run or dbt compile before serving. Long load times—exclude large seeds from docs by tagging them exposure: false.

Code Example: Quick Preview Script

# preview_docs.sh
set -e
PROJECT_DIR=$(pwd)
dbt compile --project-dir "$PROJECT_DIR"
dbt docs serve --port 8082 --open-browser

This bash script compiles models and serves docs on port 8082 with auto-open.

Why dbt docs serve is important

Reliable documentation accelerates debugging and onboarding. dbt docs serve lowers the activation energy by hosting docs locally, encouraging engineers to document and validate models every development cycle. Quick lineage visibility reduces query errors and technical debt.

dbt docs serve Example Usage


dbt docs serve --port 8081

dbt docs serve Syntax



Common Mistakes

Frequently Asked Questions (FAQs)

Is dbt docs serve suitable for production?

No. It is meant for local or ephemeral environments. For production, host the static files generated by `dbt docs generate` in a CDN or object store.

How do I change the default browser dbt opens?

The command respects your OS default browser. Change that setting at the OS level or pass `BROWSER` environment variable on Unix-like systems.

Can Galaxy open dbt docs lineage from a query?

Yes. Galaxy detects model names in your SQL and offers a "View in dbt Docs" shortcut that opens the served URL at the model anchor, streamlining investigation.

Does dbt docs serve reload on code changes?

No. You must stop and restart the command after re-compiling models to see updates.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.