devcontainers / devcontainers/features
DevContainer started from docker compose breaks `docker-in-docker` networking
- Dominant language
- Shell
- Stars
- 1.5k
- Forks
- 621
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 4
Description
Hi devcontainers features team,
I found a weird DNS behavior in the `docker-in-docker` feature. So, let's begin with a meme:

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
Contributor guide
Assessment
This issue has not been assessed yet.