My project requires three containers/services:
- web
- api
- db
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"
}