microsoft / vscode-dev-containers

NOTE: Most of the contents of this repository have been migrated to the new devcontainers GitHub org (https://github.com/devcontainers). See https://github.com/devcontainers/template-starter and https://github.com/devcontainers/feature-starter for information on creating your own!
https://aka.ms/vscode-remote
MIT License
4.7k stars 1.41k forks source link

Dev Container suddenly cannot access Internet today #1739

Open junwang-wish opened 1 year ago

junwang-wish commented 1 year ago

I could access internet in my VScode dev container yesterday, but not today. I checked the host machine (Ec2 instance) can access internet without problem by running

curl -Is www.google.com | head -n 1
> HTTP/1.1 200 OK

Yet in the dev container, it hangs due to no access to internet.

So I decided to rebuild the dev container, without any change to my .devcontainer/devcontainer.json and made no change to my Dockerfile, but rebuild started to fail due to no access to internet (My Dockerfile needs internet to install some packages, my postCreateCommand needs internet to install Python packages): .devcontainer/devcontainer.json:

{
    "name": "Test",
    "build": {
        "dockerfile": "../Dockerfile",
        "context": ".."
    },
    "runArgs": [ "--network", "host"],
    "postCreateCommand": "pip install pandas"
}

and Dockerfile:

ARG VARIANT=3.8
FROM mcr.microsoft.com/devcontainers/python:0-${VARIANT}
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
    && apt-get -y install -y libsasl2-modules libsasl2-dev

Is this related to new release of VScode? How to fix it to be able to access internet inside dev container during Dockerfile build, and also post build?

I tried removing "runArgs": [ "--network", "host"] but it also results in failure to build the dev container.

junwang-wish commented 1 year ago

This seems to only happen on my EC2 dev instance, not my Macbook, so it's extra strange

hlafaille commented 1 year ago

Same thing started happening to me today. Running Debian 12 Bookworm as the host, I can build the image by hand by running docker build, but building through VSCode seems to fail with a network error. Very strange, and I'm pulling my hair out trying to get this working as I need to work... I also had --network host included in my runArgs. Did you ever find a solution to this?