Development Software

Working with Rust in VSCode’s devcontainer

Seamlessly run your Rust programs under a development container in Visual Studio Code.



You will need to install:

  1. Visual Studio Code
  2. Docker Desktop
  3. Rust language
  4. jo (JSON output)

I use macOS as my development platform of choice, and my dot files are configured for this to work out of the box. At the time of writing, and without my dot files, I found that I needed to add the CLI command, code, to my $PATH environment variable for VSCode version 1.55.0:

export PATH="/Applications/Visual Studio$PATH"

Cargo add subcommand

At the time of writing, there’s an open ticket (Subcommand to add a new dependency to Cargo.toml #2179) for Rust to include cargo add in a standard installation of Rust. To add this to your development environment, run:

cargo install cargo-edit

Now you’ll be able to update Cargo.toml in your project folder without directly editing it. Later in this article, I demonstrate building an application with Nannou outside of devcontainer. If I wanted to add Nannou 0.15 without manually editing Cargo.toml, I would run:

cargo add nannou@0.15

VSCode Plug-ins

I installed the following plug-ins by running this command:

  1. Docker for Visual Studio Code
    Identifier: ms-azuretools.vscode-docker
  2. rust-analyzer
    Identifier: matklad.rust-analyzer
  3. CodeLLDB
    Identifier: vadimcn.vscode-lldb
  4. Code Runner
    Identifier: formulahendry.code-runner
  5. Remote – Containers
    Identifier: ms-vscode-remote.remote-containers

for pkg in \
    "ms-azuretools.vscode-docker" \
    "matklad.rust-analyzer" \
    "vadimcn.vscode-lldb" \
    "formulahendry.code-runner" \
    "ms-vscode-remote.remote-containers" \
    do code --install-extension "$pkg";

Leave a Reply

Your email address will not be published. Required fields are marked *