Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code IntelliSense enabled when developing inside a Docker container

Tags:

I'm wondering whether it is possible to have VS Code IntelliSense enabled when developing inside a Docker container where all the dependencies are locally installed?

like image 397
John Gray Avatar asked Nov 10 '17 21:11

John Gray


People also ask

Should I develop inside a Docker container?

It's not essential to develop for Docker, inside Docker. You use a Docker container as your development environment. This is especially useful if you need special software installed in your development environment.

Can I run Visual Studio in a Docker container?

The Visual Studio Code Remote - Containers extension lets you use a Docker container as a full-featured development environment. It allows you to open any folder inside (or mounted into) a container and take advantage of Visual Studio Code's full feature set.

How do I connect VS Code to Docker?

To attach to a Docker container, either select Remote-Containers: Attach to Running Container... from the Command Palette (F1) or use the Remote Explorer in the Activity Bar and from the Containers view, select the Attach to Container inline action on the container you want to connect to.


1 Answers

VS Code has recently launched its Visual Studio Code Remote - Containers extension:

The Visual Studio Code Remote - Containers extension lets you use a Docker container as a full-featured development environment. It allows you to open any folder inside (or mounted into) a container and take advantage of Visual Studio Code's full feature set.

But most importantly for your use case:

This lets VS Code provide a local-quality development experience — including full IntelliSense (completions), code navigation, and debugging — regardless of where your tools (or code) are located.

I made a screencast that shows that:

  1. The project is mounted inside a Docker container via VS Code itself
  2. An npm package ramda.js is installed from the running container
  3. VS Code IntelliSense is able to make suggestions even though the package was installed in the container.

Here's the relevant configuration file .devcontainer.json at the root of the project:

{
  "name": "My Project",
  "image": "node:12-alpine"
}

enter image description here

like image 169
customcommander Avatar answered Oct 15 '22 08:10

customcommander