thzoid
thzoid

Reputation: 195

How do I deploy a dev container without running every other service?

Below is a docker-compose.yml from Visual Studio Code "Go & PostgreSQL" development container preset (original avaiable here):

version: '3.8'

volumes:
  postgres-data:
    null

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        VARIANT: 1.18-bullseye
        NODE_VERSION: "lts/*"
    env_file:
      - .env

    volumes:
      - ..:/workspace:cached

    command: sleep infinity

    network_mode: service:db

  db:
    image: postgres:latest
    restart: unless-stopped
    volumes:
      - postgres-data:/var/lib/postgresql/data
    env_file:
      - .env

How do I set, for instance, the db service to not start along with the development container itself? Adding profile: ["foo"] or restart: no to the db service resulted in the following error:

Start: Run: docker-compose -f /home/usr/go/src/github.com/foo/go-postgres/.devcontainer/docker-compose.yml --profile * config
Stop (109 ms): Run: docker-compose -f /home/usr/go/src/github.com/foo/go-postgres/.devcontainer/docker-compose.yml --profile * config
Error: Command failed: docker-compose -f /home/usr/go/src/github.com/foo/go-postgres/.devcontainer/docker-compose.yml --profile * config
    at Ru (/home/usr/.vscode-remote-containers/dist/dev-containers-cli-0.231.6/dist/spec-node/devContainersSpecCLI.js:210:813)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async pR (/home/usr/.vscode-remote-containers/dist/dev-containers-cli-0.231.6/dist/spec-node/devContainersSpecCLI.js:182:643)
    at async dR (/home/usr/.vscode-remote-containers/dist/dev-containers-cli-0.231.6/dist/spec-node/devContainersSpecCLI.js:179:2075)
    at async IR (/home/usr/.vscode-remote-containers/dist/dev-containers-cli-0.231.6/dist/spec-node/devContainersSpecCLI.js:224:2195)
    at async Xw (/home/usr/.vscode-remote-containers/dist/dev-containers-cli-0.231.6/dist/spec-node/devContainersSpecCLI.js:224:3221)
    at async kR (/home/usr/.vscode-remote-containers/dist/dev-containers-cli-0.231.6/dist/spec-node/devContainersSpecCLI.js:224:13925)
    at async TR (/home/usr/.vscode-remote-containers/dist/dev-containers-cli-0.231.6/dist/spec-node/devContainersSpecCLI.js:224:13650)
Stop (391 ms): Run in Host: /home/usr/.vscode-server/bin/dfd34e8260c270da74b5c2d86d61aee4b6d56977/node /home/usr/.vscode-remote-containers/dist/dev-containers-cli-0.231.6/dist/spec-node/devContainersSpecCLI.js up --container-data-folder .vscode-server/data/Machine --container-system-data-folder /var/vscode-server --workspace-folder /home/usr/go/src/github.com/foo/go-postgres --workspace-mount-consistency cached --id-label vsch.local.folder=\\wsl.localhost\Ubuntu-20.04\home\usr\go\src\github.com\foo\go-postgres --id-label vsch.quality=stable --log-level debug --config /home/usr/go/src/github.com/foo/go-postgres/.devcontainer/devcontainer.json --remove-existing-container --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root t
Exit code 1
Command failed: /home/usr/.vscode-server/bin/dfd34e8260c270da74b5c2d86d61aee4b6d56977/node /home/usr/.vscode-remote-containers/dist/dev-containers-cli-0.231.6/dist/spec-node/devContainersSpecCLI.js up --container-data-folder .vscode-server/data/Machine --container-system-data-folder /var/vscode-server --workspace-folder /home/usr/go/src/github.com/foo/go-postgres --workspace-mount-consistency cached --id-label vsch.local.folder=\\wsl.localhost\Ubuntu-20.04\home\usr\go\src\github.com\foo\go-postgres --id-label vsch.quality=stable --log-level debug --config /home/usr/go/src/github.com/foo/go-postgres/.devcontainer/devcontainer.json --remove-existing-container --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true

The command above was executed by the Remote-Containers Visual Studio Code extension.

Upvotes: 0

Views: 3028

Answers (1)

mpriscella
mpriscella

Reputation: 381

You should be able to use the runServices property in devcontainer.json. According to the documentation, that will allow you to specify which services start up when opening the devcontainer.

Upvotes: 1

Related Questions