What property to use for a prebuilt vscode devcontainer
I am currently build a VSCode devcontainer to share with my team.
The container is built on a Gitlab pipeline using devcontainer build
and pushed on our private registry. Then in the repo we are pulling that container
My question is around the devcontainer.json
file used for the prebuilt container. It seems I can't find any answer nowhere.
What property can I actually use from the reference in a devcontainer build
context? From the doc, they only show a couple from an couple. But what about the others? (especially settings
)
do you know?
how many words do you know
See also questions close to this topic
-
Is it possible to use input variables in keybindings in VS Codium?
In Visual Studio Codium I want to define a command that has a variable parameter.
I want the IDE to open specific file, which name is written in another file. Assume I have the following project structure:
/home/user/myproject/ /home/user/myproject/dir1/ /home/user/myproject/dir1/problem1.py /home/user/myproject/dir1/problem2.py /home/user/myproject/dir2/problem1.py ... /home/user/myproject/pointer.txt
The
pointer.txt
contains path to the file I want to work on. For example, it contains:dir1/problem1
.I have read the documentation here. Now I created the following construction:
keybindings.json
:{ "key": "numpad3", "command": "htmlRelatedLinks.openFile", "args": { "file": "${workspaceFolder}/${input:mycatinput}.py", "method": "vscode.open", "viewColumn": 2, } },
tasks.json
:{ "version": "2.0.0", "tasks": [ { "label": "mycat", "type": "shell", "command": "cat /home/user/myproject/pointer.txt" }, ], "inputs": [ { "id": "mycatinput", "type": "command", "command": "workbench.action.tasks.runTask", "args": "mycat" } ] }
But when I press numpad3, I get an error notification with text:
Unable to open '${input:mycatinput}.py': File not found.
Am I missing something? How do I specify a variable in keybindings.json command, which itself is a result of another command (a shell command, not a vscode command).
-
Can I use multiple different commands for a single file type in coderunner?
"code-runner.executorMap": { "cpp": "cd $dir && g++ -Wall -Wextra -O2 -std=c++14 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt" },
Coderunner has a command to run .cpp code, but if I want to use another command, such as adding " < input.txt", I would have to go to settings.json to change it. Is there a way to set up multiple commands on vscode for a single kind of file so I can just simply switch without having to change settings.json?
-
How do I set the default c# file in my Visual Studio Code c# Project?
I am new to using Visual Studio Code. I have always used Visual Studio IDE in Windows. I am trying to run a simple Hello World Program on Mac with VS Code. I ran the following command
dotnet new console
which successfully created the csProj file and Program.cs file with the code
Console.WriteLine("Hello, World!");
Now by issuing dotnet run command I can get the output from this Program as well. But I have a different cs file called "Hello.cs" in the same Project location. How do I get the Hello.cs to run instead of the default "Program.cs" created bydotnet new console
command. I tried giving the following property group in the .csproj file but VS Code reports error this is reserved property.<PropertyGroup><StartupObject>Hello.HelloWorld</StartupObject></PropertyGroup>
Is there another way to choose your default startup CS File if you have multiple CS files in your Project.
-
Having trouble with declared functions in `~/.profile` not being loaded in integrated terminal shells
I have a
.profile
which is copied to /home/vscode during my container build before runningcommon-debian.sh
This is important as during container image build
common-delian.sh
will skip creating a default .profile if the file is already presentIn that profile I have a number of bash functions and some exported variables.
One of the variables relies on executing one of the declared functions, and in my shell I can see the correct variable and value is set.
This problem arises when opening a new integrated terminal in vscode. "new terminal" command
However none of my functions are available in the shell to execute. Confirmed through
typeset -F
I can run
source ~/.profile
and the functions are then available in the shell.Is there some place I can turn up logging to determine what is happening here?
Details about the install
vscode Host install is Mac M1
VERSION='0.202.6' CONTENTS_URL='https://github.com/microsoft/vscode-dev-containers/tree/main/containers/debian/history/0.202.6.md' DEFINITION_ID='debian' VARIANT='bullseye' GIT_REPOSITORY='https://github.com/microsoft/vscode-dev-containers/' GIT_REPOSITORY_RELEASE='v0.224.0' BUILD_TIMESTAMP='Fri, 25 Feb 2022 10:48:36 GMT'
Example function declaration
kconfig() { ls $HOME/.kube/configs/* | tr '\n' ':' } declare -f kconfig
Example variable making use
export KUBECONFIG="$(kconfig)"
I can confirm before sourcing .profile, this variable is set and valid and should only have come from the .profile declaration.
home folder for reference
vscode ➜ /workspace (master ✗) $ ls -al ~ total 76 drwxr-xr-x 1 vscode vscode 4096 Apr 27 18:59 . drwxr-xr-x 1 root root 4096 Feb 25 10:55 .. drwxr-xr-x 1 501 dialout 160 Mar 8 22:31 .aws -rw-r--r-- 1 vscode vscode 220 Aug 4 2021 .bash_logout -rw-r--r-- 1 vscode vscode 4665 Feb 25 10:55 .bashrc drwxr-xr-x 3 vscode vscode 4096 Apr 27 18:59 .cache drwxr-xr-x 1 501 dialout 192 Apr 25 21:41 .config drwxr-xr-x 1 501 dialout 160 Apr 27 14:20 .creds -rw-r--r-- 1 vscode vscode 500 Apr 27 18:59 .gitconfig drwx------ 2 vscode vscode 4096 Apr 27 18:59 .gnupg drwxr-xr-x 1 501 dialout 160 Mar 9 21:59 .kube drwxr-xr-x 12 vscode vscode 4096 Feb 25 10:55 .oh-my-zsh -rw-r--r-- 1 vscode vscode 2381 Apr 27 19:19 .profile drwxr-xr-x 1 vscode root 4096 Apr 27 18:59 .vscode-server drwxr-xr-x 3 vscode root 4096 Apr 27 18:26 .vscode-server-insiders -rw-r--r-- 1 vscode vscode 3897 Feb 25 10:55 .zshrc
Edit below:
Now I am copying this file in as
~/.bash_profile
There is still a .profile, vscodecommon-debian.sh
creates this if the file is not present when building the container image.vscode ➜ /workspace (master ✗) $ ls -al ~ total 80 drwxr-xr-x 1 vscode vscode 4096 Apr 27 20:08 . drwxr-xr-x 1 root root 4096 Feb 25 10:55 .. drwxr-xr-x 1 501 dialout 160 Mar 8 22:31 .aws -rw-r--r-- 1 vscode vscode 220 Aug 4 2021 .bash_logout -rw-r--r-- 1 vscode vscode 2671 Apr 27 19:57 .bash_profile -rw-r--r-- 1 vscode vscode 4665 Feb 25 10:55 .bashrc drwxr-xr-x 3 vscode vscode 4096 Apr 27 20:08 .cache drwxr-xr-x 1 501 dialout 192 Apr 25 21:41 .config drwxr-xr-x 1 501 dialout 160 Apr 27 14:20 .creds -rw-r--r-- 1 vscode vscode 500 Apr 27 20:08 .gitconfig drwx------ 2 vscode vscode 4096 Apr 27 20:08 .gnupg drwxr-xr-x 1 501 dialout 160 Mar 9 21:59 .kube drwxr-xr-x 12 vscode vscode 4096 Feb 25 10:55 .oh-my-zsh -rw-r--r-- 1 vscode vscode 807 Aug 4 2021 .profile drwxr-xr-x 1 vscode root 4096 Apr 27 20:08 .vscode-server drwxr-xr-x 3 vscode root 4096 Apr 27 20:07 .vscode-server-insiders -rw-r--r-- 1 vscode vscode 3897 Feb 25 10:55 .zshrc
also added the following to /etc/profile.d/
# This file is intended to be copied into /etc/profile.d project_profile="$HOME/.bash_profile" if [ -r $project_profile ]; then source $project_profile else echo "File not found or not readable: $project_profile" fi
none of which has had an effect on the resulting new shells perhaps ignoring vscode
docker exec -it {container} /bin/bash
still has the same results.I have also tried creating an empty terminal profile with an empty shell profile, launching vscode from that terminal window. Thinking that perhaps inherited env was causing issues.
Also set the following user setting
"terminal.integrated.inheritEnv": false,
-
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? Addingprofile: ["foo"]
orrestart: no
to thedb
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.
-
How can I bind mount to a vscode devcontainer without hard-coding it in devcontainer.json
In this question it is recommended that
.devcontainer.json
should be committed.I agree, but for one problem. I need to bind mount a local directory into my devcontainer. That requires a local path that my colleagues won't have. The purpose is to mount my GCP credentials into my devcontainer for use with the gcloud CLI.
My .devcontainer.json looks like:
{ "image": "some/image", // ... settings, extensions, forwardPorts, postCreateCommand, remoteUser, runArgs ... // Mount gcloud configuration directory "mounts": [ "source=/Users/myname/.config/gcloud,target=/gcp/config,type=bind,consistency=cached" ] }
This works, but if I commit this it'll break everybody else's setups.
How can I create a bind mount to a vscode devcontainer that's defined locally by me, without adding an entry to
.devcontainer.json
?WORKAROUNDS
One workaround is to turn this into a docker-compose setup then define a
docker-compose.developer-overrides.yml
file which doesn't get committed, but is required. But that seems like the wrong solution and there should be a settings override somewhere that I've missed.Another is to mount the user's home directory (the vscode user guide shows how to do that for both windows and linux users using:
"source=${localEnv:HOME}${localEnv:USERPROFILE},target=/host-home-folder,type=bind,consistency=cached"
...but then all users have to have their gcloud config installed in the same location in their local machine; I'm not sure if this is possible.