Use host networking while building a VSCode devcontainer

15.1k views Asked by At

How can I get VSCode to use host networking during the build of the container? In devcontainer.json, I can set

"runArgs": ["--network=host"]

but that only applies to running the container. How can I get VSCode to use host networking during the build of the container?

3

There are 3 answers

4
Oren_C On

UPDATE 2023

The solution below no longer works. According to a GitHub issue you can use this instead:

"runArgs": [
    "--network=host",
],

Original Solution (no longer works)

You need to add the following in your devcontainer.json file:

    "build": {
        "args": {
            "network": "host"
        }
    }

This property will allow you to use the host network when building.

0
Zhirun Yan On

I have met a similar problem that I want to use host proxy configuration to build.

I add this in devcontainer.json:

    "build": {
        "args": {
            "HTTP_PROXY": "your_proxy_ip:port",
        }
    }

For other config, you could do the same.

Hope it will be helpful to you.

see more details here: https://docs.docker.com/engine/reference/commandline/build/#set-build-time-variables---build-arg

0
Do-do-new On

As of now, proper solution does not exist, correspondent PR is open: https://github.com/microsoft/vscode-remote-release/issues/3545

A workaround mentioned in this PR is using initializeCommand in combination with image:

 "initializeCommand": "docker build --network host --tag my-image .",
  "image": "my-image"