Run devcontainer outside of Visual Studio Code
Are you also a big fan of Visual Studio Devcontainer? Do you also sometimes want to just run the devcontainer outside of Visual Studio Code? Me also! That is why I have created this simple bash script. The script parses the
devcontainer.json file and runs the docker container outside of Visual Studio Code.
How does it work?
The script can be run in any workspace the contains the
.devcontainer configuration folder. On start, it parses several different options from the
devcontainer.json file, builds the dockerfile, and starts the container. The script mounts the current folder into the container into the
/workspaces/$currentfolder path. Same as Visual Studio Code does.
The following options from the
devcontainer.json are supported:
dockerFileuses the defined dockerfile.
settings["terminal.integrated.shell.linux"]uses the defined shell.
forwardPortspublished the defined ports to the host.
remoteEnvuses the defined environment variables.
remoteUserstarts the shell with the defined user.
How to install?
You can install the devcontainer script by either downloading the script and place it into a folder in you $PATH variable or you can use the following command to download and install the script.
sudo sh -c 'curl -s https://raw.githubusercontent.com/BorisWilhelms/devcontainer/main/devcontainer.sh > /usr/local/bin/devcontainer && chmod +x /usr/local/bin/devcontainer'
The script uses jq to parse the
devcontainer.json. Therefore it must be installed.
jqexpects a valid JSON file, all possible JSON error (e.g.
,without following properties) has to be corrected. The script will strip all comments (
//) to make it more valid.