Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use host networking while building a VSCode devcontainer

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?

like image 928
Dan Hook Avatar asked Nov 16 '25 21:11

Dan Hook


2 Answers

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.

like image 77
Oren_C Avatar answered Nov 19 '25 13:11

Oren_C


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"
like image 38
Do-do-new Avatar answered Nov 19 '25 13:11

Do-do-new



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!