[英]VSCode Remote Container - extensions not installing on dev container using docker-compose
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 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 .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. .devontainer.json
中列出的扩展列表是我想要安装在开发容器中的扩展列表。 Any help is appreciated!任何帮助表示赞赏!
According to the Visual Studio Code documentation , the two files need to be located in a directory .devcontainer
in the workspace root.根据Visual Studio Code 文档,这两个文件需要位于工作区根目录中的
.devcontainer
目录中。
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).如果您在本地机器上使用 Cntlm 之类的
authenticating
代理,请将其配置为侦听172.17.0.1
(Docker 接口)。 Then define the http_proxy
and https_proxy
environment variables for the container.然后为容器定义
http_proxy
和https_proxy
环境变量。 For example, in devcontainer.json
:例如,在
devcontainer.json
:
"containerEnv": {
"http_proxy": "http://172.17.0.1:3128",
"https_proxy": "http://172.17.0.1:3128"
}
Or in docker-compose.yaml
或者在
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:或者配置
docker-compose.yaml
使容器使用主机网络:
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
:例如,在
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).如果您使用的不是本地代理,而是网络内部的远程代理,则无论容器的网络配置(主机或默认)如何,您都可以执行后者。
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).
本地代理设置不会在容器内重用,这可能会阻止扩展工作,除非配置了适当的代理信息(例如具有适当代理信息的全局 HTTP_PROXY 或 HTTPS_PROXY 环境变量)。
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)"
.我可以通过在 'devcontainer.json':
"--net=host", "--env=https_proxy=(your_proxy_host:port)"
中附加到runArgs
来设置代理环境变量。
Alternatively, if host-access is not required for the proxy, you can just append to '.devcontainer/Dockerfile':或者,如果代理不需要主机访问,您可以将 append 设置为“.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).从您的应用程序进行网络访问(不仅仅是 vscode 扩展)也可能需要以这种方式启用代理访问。
See also: How do I pass environment variables to Docker containers?另请参阅:如何将环境变量传递给 Docker 容器?
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:
解决方案是让容器访问代理服务器并设置 HTTP proxy strict SSL:
"settings": {
"http.proxy": "(your_proxy_host:port)",
"http.proxyStrictSSL": false
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.