File tree Expand file tree Collapse file tree 3 files changed +20
-34
lines changed Expand file tree Collapse file tree 3 files changed +20
-34
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " FastAPI Jinja2 Postgres WebApp" ,
3+ "image" : " mcr.microsoft.com/devcontainers/python:3.13-bookworm" ,
34 "workspaceFolder" : " /workspaces/${localWorkspaceFolderBasename}" ,
45
5- // Ensure .env exists before Docker Compose processes env_file entries
6- "initializeCommand" : " bash \" ${localWorkspaceFolder}/.devcontainer/ensure-env.sh\" " ,
6+ "features" : {
7+ "ghcr.io/devcontainers/features/docker-outside-of-docker:1" : {}
8+ },
79
8- // Start the Postgres sidecar using the existing compose file
9- "dockerComposeFile" : [
10- " ../docker-compose.yml" ,
11- " docker-compose.yml"
10+ "runArgs" : [
11+ " --add-host=host.docker.internal:host-gateway"
1212 ],
13- "service" : " app" ,
14- "runServices" : [" db" ],
15- "shutdownAction" : " stopCompose" ,
1613
17- // Forward common app/db ports
1814 "forwardPorts" : [8000 , 5432 ],
1915 "portsAttributes" : {
2016 "8000" : { "label" : " FastAPI" , "onAutoForward" : " openBrowser" },
2117 "5432" : { "label" : " PostgreSQL" }
2218 },
2319
24- // Prepare env, install uv, and sync deps
20+ "initializeCommand" : " bash \" ${localWorkspaceFolder}/.devcontainer/ensure-env.sh\" " ,
21+ "postStartCommand" : " docker compose -f .devcontainer/docker-compose.yml up -d" ,
2522 "postCreateCommand" : " bash .devcontainer/init-env.sh && curl -LsSf https://astral.sh/uv/install.sh | sh && ~/.local/bin/uv sync" ,
2623
2724 "customizations" : {
3330 }
3431 }
3532}
36-
Original file line number Diff line number Diff line change 11services :
2- app :
3- image : mcr.microsoft.com/devcontainers/python:3.13-bookworm
4- container_name : fastapi-jinja2-postgres-webapp-app
5- volumes :
6- - ..:/workspaces/${localWorkspaceFolderBasename}:cached
7- working_dir : /workspaces/${localWorkspaceFolderBasename}
8- depends_on :
9- - db
10- command : sleep infinity
11-
12- # Override/augment settings for the db service defined in the root compose file
132 db :
14- # Avoid requiring a project-level .env during compose evaluation
15- env_file : []
3+ image : postgres:16
4+ restart : unless-stopped
5+ ports :
6+ - " 5432:5432"
167 environment :
178 POSTGRES_USER : ${DB_USER:-postgres}
189 POSTGRES_PASSWORD : ${DB_PASSWORD:-postgres}
1910 POSTGRES_DB : ${DB_NAME:-fastapi-jinja2-postgres-webapp}
20- ports :
21- - " 5432:5432"
22-
23- # Note: The 'db' service is defined in the repository root docker-compose.yml.
24- # This file is merged with that one via devcontainer.json dockerComposeFile array.
11+ volumes :
12+ - pgdata:/var/lib/postgresql/data
2513
14+ volumes :
15+ pgdata :
Original file line number Diff line number Diff line change @@ -13,11 +13,11 @@ if [ ! -f ".env" ]; then
1313 fi
1414fi
1515
16- # Ensure DB_HOST points to the compose service name for in- container access
16+ # Ensure DB_HOST points to host.docker.internal for DooD sibling container access
1717if grep -q ' ^DB_HOST=' .env; then
18- sed -i ' s/^DB_HOST=.*/DB_HOST=db /' .env
18+ sed -i ' s/^DB_HOST=.*/DB_HOST=host.docker.internal /' .env
1919else
20- echo ' DB_HOST=db ' >> .env
20+ echo ' DB_HOST=host.docker.internal ' >> .env
2121fi
2222
2323generate_secret () {
4242 echo " SECRET_KEY=$( generate_secret) " >> .env
4343fi
4444
45- echo " Environment prepared. DB_HOST set to 'db ' and SECRET_KEY ensured."
45+ echo " Environment prepared. DB_HOST set to 'host.docker.internal ' and SECRET_KEY ensured."
4646
You can’t perform that action at this time.
0 commit comments