Reputation: 7088
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
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
Reputation: 558
@Dan Hook
You need the following in devcontainer.json
"build": {
"options": ["--network=host"]
}
Upvotes: 3
Reputation: 761
The solution below no longer works. According to a GitHub issue you can use this instead:
"runArgs": [
"--network=host",
],
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
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
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