0

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.

thzoid
  • 185
  • 11
  • "docker-compose up service_name" doesn't work? – Sergey Nazarov Apr 25 '22 at 20:50
  • It does but this image should preferrably work with the Remote-Containers extension (which runs its own command) – thzoid Apr 25 '22 at 20:55
  • you could split the services into multiple compose files. https://runnable.com/docker/advanced-docker-compose-configuration#:~:text=Using%20Multiple%20Docker%20Compose%20Files,way%20to%20share%20common%20configurations. – THX1138 Apr 25 '22 at 21:07
  • @THX1138 if `db` is not defined on the same `docker-compose.yml` as the `app` service, `network_mode: service:db` fails. How would they, in that case, run on the same network? – thzoid Apr 25 '22 at 22:06
  • @thzoid you can create an external network and set the networks property to use that network. Each service definition has a `networks` array property which you can use to specify the network(s) you want each service to connect to. https://docs.docker.com/compose/networking/ – THX1138 Apr 26 '22 at 15:07

1 Answers1

0

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.

mpriscella
  • 361
  • 3
  • 12