12

I am having trouble getting extensions installed in the dev container using "Remote - Containers". I do not know if it's a bug, incorrect configuration on my end, or intended behaviour. Down below is my current configuration, both files are located in the root folder of the project.

docker-compose.yml

version: "3.7"

services:
  api:
    image: node:12
    restart: always
    ports:
      - ${API_PORT}:3000
    volumes:
      - .:/usr/app
      - /usr/app/node_modules
    working_dir: /usr/app
    command: bash -c "yarn && yarn dev"

.devcontainer.json

{
    "dockerComposeFile": "docker-compose.yml",
    "service": "api",
    "workspaceFolder": "/usr/app",
    "extensions": [
        "eamodio.gitlens",
        "formulahendry.auto-rename-tag",
        "coenraads.bracket-pair-colorizer-2",
        "kumar-harsh.graphql-for-vscode",
        "esbenp.prettier-vscode",
        "ms-vscode.vscode-typescript-tslint-plugin",
        "visualstudioexptteam.vscodeintellicode"
    ]
}

The list of extensions listed in the .devontainer.json are the ones I want to have installed in the dev container. Any help is appreciated!

HaaLeo
  • 10,065
  • 3
  • 44
  • 55
rosengrenen
  • 731
  • 6
  • 21

3 Answers3

12

According to the Visual Studio Code documentation, the two files need to be located in a directory .devcontainer in the workspace root.

I still had issues installing the extensions while working from behind a corporate proxy. The solution was to give the container access to the proxy server:

If you use an authenticating proxy like Cntlm on your local machine, configure it to listen on 172.17.0.1 (the Docker interface). Then define the http_proxy and https_proxy environment variables for the container. For example, in devcontainer.json:

"containerEnv": { 
  "http_proxy": "http://172.17.0.1:3128",
  "https_proxy": "http://172.17.0.1:3128"
}

Or in docker-compose.yaml

services:
  devcontainer:
    environment:
      http_proxy: http://172.17.0.1:3128
      https_proxy: http://172.17.0.1:3128

Or configure docker-compose.yaml to make the container use the host network:

services:
  devcontainer:
    network_mode: host

Then you can just pass the same proxy variables into the container as used on the host. For example, in the docker-compose.yaml:

services:
  devcontainer:
    environment:
      http_proxy: $http_proxy
      https_proxy: $https_proxy

If you are not using a local, but rather a remote proxy inside of your network, you can do the latter regardless of the container's network configuration (host or default).

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
clssn
  • 121
  • 1
  • 4
  • 2
    This is a really nice first post. Thank you for putting so much detail into it. – Jeremy Caney May 08 '20 at 01:22
  • Was going around in circles and needed to be spoonfed that 172.17.0.1 was a Docker-relevant interface to believe this approach was worth trying. Thanks for the guidance! – esg May 02 '23 at 18:30
0

This answer is only applicable if your network environment requires the use of a proxy server.

According to "Known limitations" of "Developing inside a Container"...

Local proxy settings are not reused inside the container, which can prevent extensions from working unless the appropriate proxy information is configured (for example global HTTP_PROXY or HTTPS_PROXY environment variables with the appropriate proxy information).

I was able to set the proxy environment variables by appending to runArgs in 'devcontainer.json': "--net=host", "--env=https_proxy=(your_proxy_host:port)".


Alternatively, if host-access is not required for the proxy, you can just append to '.devcontainer/Dockerfile':

ENV https_proxy=(your_proxy_host:port)

Enabling proxy access in this way may also be necessary for network access from your application (not just for vscode extensions).

See also: How do I pass environment variables to Docker containers?

Brent Bradburn
  • 51,587
  • 17
  • 154
  • 173
0

I also have issues installing the extensions while working from behind a corporate proxy. The solution was to give the container access to the proxy server and set HTTP proxy strict SSL:

"settings": {
    "http.proxy": "(your_proxy_host:port)",
    "http.proxyStrictSSL": false
},
Nejc Galof
  • 2,538
  • 3
  • 31
  • 70