Visual Studio Code is an open source IDE from Microsoft that has a robust ecosystem of plugins and supposes most development languages.
Using VSC with Containers
- There is a step-by-step tutorial from Microsoft on using VSC with Docker that I’d recommend.
- Official Documentation is available.
- VSC is able to provide an experience that emulates local development.
- You’ll need to install Docker to use VSC with Containers.
- Once Docker is installed right click on the Docker taskbar icon and choose Settings / Preferences > Shared Drives / File Sharing. You’ll need to add any drives you intend to have projects on to this sharing.
- I recommend installing the Docker extension for VSC from Microsoft, though this is not required.
- You will need to install the Remote Development pack from Microsoft which includes all the new remote development tools or you can strip it down to only Remote – Containers.
- To quickly try out this functionality see the Quick Start: Try a Dev Container documentation.
- To create a container for an existing project see Quick Start: Open an Existing Folder in a Container. Microsoft includes a nice selection of Docker containers though you can also use your own.
- devcontainer.json tells VSC how to access (or create) a development container, in all of the above referenced instances a devcontainer.json file is either created or an existing one used.
- Use Remote-Containers: Add Development Container Configuration Files… command to add the file to a folder.
- When you edit a devcontainer.json VSC does not reload the container by default, you’ll need to issue a command to do so.
- Remote-Containers: Rebuild Container.
Attaching to Running Containers
- If one already has a container one can attach to it.
- This will not create / use a devcontainer.json but extensions that should be installed can be configured in settings.json.
- Remote-Containers: Attach to Running Container OR use the Docker extension
Managing Docker Containers
- One can use the Docker extension
- Or one can use the Docker CLI
- Or one can use Docker Compose
- Extensions that don’t affect the VS Code UI can be installed directly on the container and don’t need to also be installed on the local VSC. This allows one to fully swap toolchains by connecting to a different container.
- To permanently add a forwarded port use devcontainer.json: edit the appPort property
- Or Dockerfile, or Docker Compose file: edit the ports mapping in docker-compose.yml
- To temporarily forward for the session use Remote-Containers: Forward Port from Container…
- Select the desired port (if there aren’t any listed there aren’t any speaking).
Opening a Terminal
- Any terminal opened after opening a folder in a container will start in the remote system.
Debugging in a Container
- Runs the same as locally once the folder has been opened in a container.
Container Specific Settings
- Preferences: Open Remote Settings after a folder has been opened in a container.
- Or by selecting Remote tab in the settings editor.
Sharing Git Credentials with Your Container
- If you use HTTPS to clone repos and have a credential helper configured in local OS, no setup is needed.
- If using SSH, see the documentation.