Replies: 1 comment 1 reply
-
|
Hi 👋 I have always added the However, according to my knowledge, the two code blocks would not produce the same behavior. In the first code block, the The |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I've come across multiple Docker Compose samples where the main container uses
network_mode: service: db. I think there are 2 reasons for this:to enable usage of "localhost" in connection strings, no matter where you run your codehttps://containers.dev/guide/dockerfile#docker-compose-image
Details
However I don't quite understand why the devcontainer uses the db's network adapter rather than the other way around.
It makes more sense to me to make this work the other way around by attaching the db to the devcontainer's network adapter.
version: '3.8' services: devcontainer: image: mcr.microsoft.com/devcontainers/base:ubuntu volumes: - ../..:/workspaces:cached - network_mode: service:db command: sleep infinity db: image: postgres:latest restart: unless-stopped volumes: - postgres-data:/var/lib/postgresql/data + network_mode: service:devcontainer environment: POSTGRES_PASSWORD: postgres POSTGRES_USER: postgres POSTGRES_DB: postgres volumes: postgres-data:Does this work just as well, or is there a reason why you wouldn't do this?
Beta Was this translation helpful? Give feedback.
All reactions