14

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!

1
  • It worked when I set it up on a different computer. It probably was an issue with caching or similar. Commented May 5, 2019 at 17:24

3 Answers 3

13

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).

Sign up to request clarification or add additional context in comments.

2 Comments

This is a really nice first post. Thank you for putting so much detail into it.
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!
2

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
},

1 Comment

Three years later, same issue
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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.