Reputation: 6441
My project requires three containers/services:
The web
and api
should both be built from their respective Dockerfiles:
api/Dockerfile
web/Dockerfile
The api
and web
directories contain the source code for the respective services.
How can I setup VSCode so I build both the web and the api containers, choosing which service to open remotely via the devcontainer.json
file?
My devcontainer config looks like this:
# .devcontainer/docker-compose.yml
services:
web:
build:
context: ../web
dockerfile: Dockerfile
ports:
- 3000:3000
links:
- api
api:
build:
context: ../api
dockerfile: Dockerfile
ports:
- 3001:3001
links:
- db
db:
image: postgres
restart: unless-stopped
ports:
- 5432:5432
environment:
POSTGRES_PASSWORD: pass
POSTGRES_USER: user
POSTGRES_DB: data
# .devcontainer/devcontainer.json
{
"name": "App",
"dockerComposeFile": "docker-compose.yml",
"service": "web",
"workspaceMount": "source=${localWorkspaceFolder}/web,target=/workspace,type=bind,consistency=delegated",
"workspaceFolder": "/workspace"
}
Upvotes: 2
Views: 1921
Reputation: 206
I'm no expert in this field, but I would guess that you're mixing approaches here.
Alt1 (The one you're asking for)
Alt2 (The one you have done)
List of properties: https://code.visualstudio.com/docs/remote/devcontainerjson-reference#_devcontainerjson-properties
Upvotes: 2