17

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?

Dan Hook
  • 6,769
  • 7
  • 35
  • 52

3 Answers3

3

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"
Do-do-new
  • 794
  • 8
  • 15
2

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.

Oren_C
  • 565
  • 7
  • 22
0

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