devcontainers / devcontainers/features

DevContainer started from docker compose breaks `docker-in-docker` networking

Offen
#568 5 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Shell
Sterne
1.5k
Forks
622
Ø Merge
6 T. 53 Min.
Gemergte PRs (30 T.)
9

Beschreibung

Hi devcontainers features team,

I found a weird DNS behavior in the `docker-in-docker` feature. So, let's begin with a meme:

![image](https://github.com/devcontainers/features/assets/11291885/2f728dee-f74e-4031-8c4a-359cb4cf748e)

So now let's start with the issue.
`docker-in-docker` works fine in `devcontainers` that just use the image option to boot. So, if you `.devcontainers.json` looks like that:

```json
{
"name": "Debian",
"image": "mcr.microsoft.com/devcontainers/base:bullseye",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
}
}
```

Then DNS should work fine and if you run the following command inside the devcontainer:

```bash
docker run ubuntu /bin/bash -c "cat /etc/resolv.conf"
```

you will get:

```bash
# DNS requests are forwarded to the host. DHCP DNS options are ignored.
nameserver 192.168.65.7
```

This name server is an IP that is generated by your docker desktop installation and will redirect DNS queries to the DNS server that is configured in your windows host.

If you now change the model of your `devcontainer.json` to use a compose file to build the devcontainer, like shown in the following example:

```json
{
"name": "Debian",
"dockerComposeFile": "devcontainer.docker-compose.yml",
"service": "devcontainer",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
}
}
```

you will see are diffrent behaivior then before with the same command. So, let's run the command:

```bash
docker run ubuntu /bin/bash -c "cat /etc/resolv.conf"
```

again, and let’s see what the output is:

```bash
options ndots:0

nameserver 8.8.8.8
nameserver 8.8.4.4
```

That looks quite different and can be also really bad. For example, in my company it's not allowed to make DNS request to the internet. We are forced to use the internal DNS server. So, in this situation the `ubuntu` container is basically offline because he can't resolve names anymore.

The expected behavior would be of course that we would have the same output as before we changed to the compose file.

hope this is enough information to get this fixed.

Best regards

Some Metainforamtion:

DemoRepo for this bug: https://github.com/paule96/DevContainerSampleBug
WSL version: 1.2.5.0
Kernel version: 5.15.90.1
WSLg version: 1.0.51
MSRDC version: 1.2.3770
Direct3D version: 1.608.2-61064218
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.19045.2965
Visual Studio Code: 1.78.2 (user setup)
DevContainers Extension: v0.292.0

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Reproduziere das Verhalten mithilfe der `.devcontainer.json`-Konfigurationen, von `devcontainer.docker-compose.yml` und des im Bericht verlinkten Demo-Repositorys. Führe den Befehl `docker run ubuntu /bin/bash -c "cat /etc/resolv.conf"` in beiden Setups aus und verfolge den Unterschied beim docker-in-docker-Netzwerk. Als erledigt gilt, wenn mit Compose gestartete Container den Host-DNS oder den konfigurierten internen DNS anstelle der angezeigten öffentlichen Nameserver verwenden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
docker, docker-compose, shell
Bereich
devops, infrastructure, networking
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.