Skip to content

Instantly share code, notes, and snippets.

@dltm-markwan
Last active September 30, 2025 15:13
Show Gist options
  • Select an option

  • Save dltm-markwan/0d6b780ac1a98cf401ff5e6059175145 to your computer and use it in GitHub Desktop.

Select an option

Save dltm-markwan/0d6b780ac1a98cf401ff5e6059175145 to your computer and use it in GitHub Desktop.
dev containers for dbt

Setup dbt dev containers in 10 minutes

Pre-requites

  1. Docker - https://docs.docker.com/desktop/install/mac-install/
  2. VSCode
  3. VSCode extension: Dev Containers

Instructions

This gist will contain two options - dbt Core or dbt Cloud CLI The following steps are required by both:

  1. Create a new folder in your dbt code repository called .devcontainer
  2. Copy devcontainer.json, postCreateCommand.sh, requirements.txt into .devcontainer/
  3. If core then copy profiles.yml. If cloud then copy dbt_cloud.yml. You can also choose to place both inside .devcontainer/
  4. Update the yml file with your own connection details
  5. Update the PLATFORM in postCreateCommand.sh - either "cloud" or "core"
  6. Open up the dbt code repository in VS Code ensuring that .devcontainer/ is within the root directory
  7. Click "Open Remote Window" button in the bottom left

After the initialisation runs you should be in a Development Docker Container woohoo! Try running dbt --help to check that the correct dbt is installed

If using core you may need to reload the VSCode window for dbt Power User to work. You can do this by pressing F1 and running "Reload Window".

Notes

  • The profiles.yml and dbt_cloud.yml are symlinked meaning you can change the values directly to the files inside .devcontainer/ and they will be reflected in ~/.dbt - no copying required.
  • Rebuild the container if you make changes to postCreateCommand.sh
version: "1"
context:
active-project: "206289"
active-host: "cloud.getdbt.com"
projects:
- project-id: "289578"
account-host: "cloud.getdbt.com"
api-key: "<YOUR-API-KEY>"
- project-id: "206289"
account-host: "cloud.getdbt.com"
api-key: "<YOUR-API-KEY>"
- project-id: "51"
account-host: "au.dbt.com"
api-key: "<YOUR-API-KEY>"
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "Python 3",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bullseye",
"features": {
"ghcr.io/devcontainers-contrib/features/curl-apt-get:1": {}
},
"containerEnv": {
"DBT_CLOUD_API_KEY": "${localEnv:DBT_CLOUD_API_KEY}",
},
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "./.devcontainer/postCreateCommand.sh",
"customizations": {
"vscode": {
"extensions": [
"innoverio.vscode-dbt-power-user",
"ms-python.black-formatter",
"GitHub.copilot",
"esbenp.prettier-vscode",
"ms-python.python",
"redhat.vscode-yaml",
"eamodio.gitlens"
]
}
}
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
BIN_DIR="/usr/local/bin"
CLI_VERSION="0.32.5"
PLATFORM="core" #takes either "core" or "cloud"
export PATH=$PATH:$$BIN_DIR
echo "export PATH=\$PATH:$BIN_DIR" >> ~/.bashrc
. ~/.bashrc
mkdir /home/vscode/.dbt/
if [ "$PLATFORM" = "core" ]
then
echo "=====> Installing dbt Core and symlinking profiles.yml"
if [ ! -f /workspaces/sa-standard-shared-demo/.devcontainer/profiles.yml ]; then
echo "Could not find profiles.yml in .devcontainer/. Please create profiles.yml and rebuild the container"
exit
fi
ln -s /workspaces/sa-standard-shared-demo/.devcontainer/profiles.yml /home/vscode/.dbt/profiles.yml
pip install dbt-snowflake
fi
if [ "$PLATFORM" = "cloud" ]
then
echo "=====> Installing dbt Cloud and symlinking dbt_cloud.yml"
curl -LO "https://github.com/dbt-labs/dbt-cli/releases/download/v${CLI_VERSION}/dbt_${CLI_VERSION}_linux_amd64.tar.gz"
sudo tar -xzf "dbt_${CLI_VERSION}_linux_amd64.tar.gz" -C "$BIN_DIR" dbt
if [ ! -f /workspaces/sa-standard-shared-demo/.devcontainer/dbt_cloud.yml ]; then
echo "Could not find dbt_cloud.yml in .devcontainer/. Please create dbt_cloud.yml to continue and rebuild the container"
exit
fi
ln -s /workspaces/sa-standard-shared-demo/.devcontainer/dbt_cloud.yml /home/vscode/.dbt/dbt_cloud.yml
rm "dbt_${CLI_VERSION}_linux_amd64.tar.gz"
. ~/.bashrc
fi
pip install -r .devcontainer/requirements.txt
jaffle_shop:
outputs:
dev:
account: zna84829
database: sa_mark_wan
password: <snowflake-password>
role: TRANSFORMER
schema: dev
threads: 4
type: snowflake
user: MARK_WAN
warehouse: transforming
target: dev
tpch:
outputs:
default:
account: zna84829
database: sa_mark_wan
password: <snowflake-password>
role: TRANSFORMER
schema: dbt_c_mwan
threads: 4
type: snowflake
user: MARK_WAN
warehouse: transforming
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment