VS Code Dev Container download failures: where should the proxy go for pulls, builds, and runtime?

December 24, 2024

Your computer can reach the package repository, yet VS Code stalls on a download during Reopen in Container. Before asking how to get the container online, identify who is doing the downloading. If the base image has not arrived, the dev container does not yet have a terminal. Conversely, if the window is already open and only pip install times out, you can investigate in that terminal. If the log still says Podman is missing or the socket is unreachable, start with how VS Code connects to Podman.

Where should I start reading the log?

Open Dev Containers: Show Container Log from the command palette. Find the first download error and look immediately above it for the operation in progress. Suppose the project uses a Dockerfile, a text recipe for building an image. Downloads can originate in three places.123

Log entry or actionWhat is using the network?Where to check
Pulling the base image named in FROM failsThe container engine is downloading files from the registryPull the same image through the same engine and connection. If a background service does the pull, check its registry access and proxy settings.
The image was found but RUN apt-get update failsA temporary process started by the builder is contacting package sourcesCheck the proxy address, certificates, and network options used by the build step.
The project is open in VS Code but pip install fails in the terminalA program inside the running dev container is contacting a package repositoryCheck the target URL, the proxy variables the program reads, and its certificates in that terminal.

Ordinary containers can usually make outbound connections over their default network. Publishing a port addresses the opposite direction, for example when you want your desktop browser to reach a development server inside the container. For a download timeout, start with the corresponding row above.4

Why does a manual image pull work while a background job fails?

A GitLab forum user could run podman pull manually through a corporate proxy, but the Runner executing the build reported no route to host. In post 4, the author reported success after configuring the proxy for the unprivileged user’s Podman service process. In post 6, scruel wrote, “I still won’t be able to pull with proxy after applied the same configuration”. Both observations matter. The manual command tests your terminal environment. For the background job, find out which service it contacts and who sends the request to the registry. Although this example was about GitLab Runner, the same question helps locate the downloader in a local VS Code setup.25

How do I pass the same proxy address to the build and the terminal?

A proxy forwards requests to a destination site on a program’s behalf. Suppose your company supplies an address that both the build environment and the container can reach, and VS Code starts with HTTPS_PROXY in its environment. Here is a Dockerfile-based project configuration. It assumes the downloader reads the uppercase variable and the Dockerfile is next to devcontainer.json.13

{
  "build": {
    "dockerfile": "Dockerfile",
    "args": { "HTTPS_PROXY": "${localEnv:HTTPS_PROXY}" }
  },
  "containerEnv": {
    "HTTPS_PROXY": "${localEnv:HTTPS_PROXY}"
  }
}

${localEnv:HTTPS_PROXY} reads the value from the environment that launched the dev container tools. build.args passes it to the builder for Dockerfile download steps. containerEnv provides it to the running container. To affect just terminals, tasks, and debuggers started by VS Code in the container, use remoteEnv. If a tool reads lowercase https_proxy, pass the variable that tool actually reads. After editing, run Dev Containers: Rebuild Container and retry the failed step.16

Two other problems are easy to confuse. If the proxy listens only on the host’s 127.0.0.1, a program in an isolated network contacts itself at that address. If the error instead says the certificate issuer is untrusted, check which certificates the downloader trusts. The corporate proxy described by Bjego reissued HTTPS certificates, so he obtained the company root certificate from the administrator to allow the relevant environment to verify the issuer. Passing an address alone cannot establish certificate trust.43

Why does a Dockerfile RUN still fail after adding runArgs?

This is what Dan Hook encountered on Stack Overflow. He had set "runArgs": ["--network=host"], but it was the build step that needed the host network. For Dockerfile-based projects, Kamal Joshi put "options": ["--network=host"] inside build. These options are passed to the build command. Putting network under build.args would merely send a build variable named network.781

Podman describes its build network option as follows: “Sets the configuration for network namespaces when handling RUN instructions.” By default build processes have an isolated network view. With host they share the engine host’s network, which also broadens access to services on that host. On native Linux this may allow a RUN step to reach a proxy bound only to host loopback. With Podman in a VM, the host in question is the VM. Consider this option only if the download depends on that path. Rebuild and confirm that the same RUN instruction that failed actually executes and succeeds, rather than being served from cache.4

Footnotes

  1. Development Containers contributors. (n.d.). Dev Container metadata reference. Development Containers,Dockerfile-specific properties。 ↩ ↩2 ↩3 ↩4

  2. garlicbrehd357. (2023, October 4–5). Proxy for podman in podman setup. GitLab Forum,提问及第 4 楼。 ↩ ↩2

  3. Bjego. (2021, December 10). VSCode DevContainers with a corporate proxy. Medium,The problem with the certificates、File contents。 ↩ ↩2 ↩3

  4. Podman contributors. (n.d.). podman-build. Podman 文档,--network,首段及 host 模式。 ↩ ↩2 ↩3

  5. scruel. (2024, June 19). Reply to “Proxy for podman in podman setup”. GitLab Forum,第 6 楼,全文。 ↩

  6. Microsoft. (n.d.). Environment variables. Visual Studio Code 文档,Option 1: Add individual variables。 ↩

  7. Hook, D. (2020, September 25). Use host networking while building a VSCode devcontainer. Stack Overflow,问题正文。 ↩

  8. Joshi, K. (2024, May 14). Answer to “Use host networking while building a VSCode devcontainer”. Stack Overflow,构建选项示例。 ↩

© 2024 borui. All rights reserved. This content may be freely reproduced, displayed, modified, or distributed with proper attribution to borui and a link to the article: borui (2024-12-24). VS Code Dev Container download failures: where should the proxy go for pulls, builds, and runtime?. https://caiborui.com/blog/2024-12-24-zh-dev-container-build-network-proxy-entrans

@misc{borui2024-1264a180,
  author = {borui},
  title = {{VS Code Dev Container download failures: where should the proxy go for pulls, builds, and runtime?}},
  year = {2024},
  publisher = {borui's blog},
  url = {https://caiborui.com/blog/2024-12-24-zh-dev-container-build-network-proxy-entrans}
}