Dan Hook
Dan Hook

Reputation: 7088

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?

Upvotes: 19

Views: 26263

Answers (5)

IdanB
IdanB

Reputation: 333

updated solution for 2024 (in case someone come across this thread)
place inside devcontainer.json the following line:

"initializeCommand": [
    "docker", "build", "--network=host",".devcontainer"
],

worked for me

Upvotes: 0

Kamal Joshi
Kamal Joshi

Reputation: 558

@Dan Hook

You need the following in devcontainer.json

"build": {
    "options": ["--network=host"]
}

Upvotes: 3

Oren_C
Oren_C

Reputation: 761

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.

Upvotes: 8

Do-do-new
Do-do-new

Reputation: 992

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"

Upvotes: 4

Zhirun Yan
Zhirun Yan

Reputation: 11

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

Upvotes: 1

Related Questions