Skip to content

Commit d979901

Browse files
CopilotKaniska244
andcommitted
fix: update javascript-node-postgres network config and postgres volume mount
Replace network_mode: service:db with bridge network (app-network) to fix DNS resolution failures in CI. Update postgres volume mount from /var/lib/postgresql/data to /var/lib/postgresql for PostgreSQL 18+ compatibility. Update NOTES.md to reflect hostname db instead of localhost. Co-authored-by: Kaniska244 <[email protected]>
1 parent c12ea2e commit d979901

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

src/javascript-node-postgres/.devcontainer/docker-compose.yml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
version: '3.8'
1+
volumes:
2+
postgres-data:
23

34
services:
45
app:
@@ -12,17 +13,30 @@ services:
1213
# Overrides default command so things don't shut down after the process ends.
1314
command: sleep infinity
1415

15-
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
16-
network_mode: service:db
16+
# Use proper Docker networking instead of network_mode: service:db
17+
# to ensure reliable DNS resolution in all environments
18+
depends_on:
19+
db:
20+
condition: service_healthy
21+
networks:
22+
- app-network
1723

1824
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
1925
# (Adding the "ports" property to this file will not forward from a Codespace.)
2026

2127
db:
2228
image: postgres:latest
2329
restart: unless-stopped
30+
networks:
31+
- app-network
32+
healthcheck:
33+
test: ["CMD-SHELL", "pg_isready -U postgres"]
34+
interval: 10s
35+
timeout: 5s
36+
retries: 5
37+
start_period: 30s
2438
volumes:
25-
- postgres-data:/var/lib/postgresql/data
39+
- postgres-data:/var/lib/postgresql
2640
environment:
2741
POSTGRES_PASSWORD: postgres
2842
POSTGRES_USER: postgres
@@ -31,5 +45,6 @@ services:
3145
# Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally.
3246
# (Adding the "ports" property to this file will not forward from a Codespace.)
3347

34-
volumes:
35-
postgres-data:
48+
networks:
49+
app-network:
50+
driver: bridge

src/javascript-node-postgres/NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This template references an image that was [pre-built](https://containers.dev/im
55

66
## Using this template
77

8-
This definition creates two containers, one for Node.js and one for PostgreSQL. You will be connected to the Node.js container, and from within that container the PostgreSQL container will be available on **`localhost`** port 5432. The default database is named `postgres` with a user of `postgres` whose password is `postgres`, and if desired this may be changed in `docker-compose.yml`. Data is stored in a volume named `postgres-data`.
8+
This definition creates two containers, one for Node.js and one for PostgreSQL. You will be connected to the Node.js container, and from within that container the PostgreSQL container will be available on **`db`** port 5432. The default database is named `postgres` with a user of `postgres` whose password is `postgres`, and if desired this may be changed in `docker-compose.yml`. Data is stored in a volume named `postgres-data`.
99

1010
While the definition itself works unmodified, it uses the `mcr.microsoft.com/devcontainers/javascript-node` image which includes `git`, `eslint`, `zsh`, [Oh My Zsh!](https://ohmyz.sh/), a non-root `vscode` user with `sudo` access, and a set of common dependencies for development.
1111

0 commit comments

Comments
 (0)