devcontainers / devcontainers/features
Docker-in-docker allow two devcontainers' sub-containers to speak
- Lingua principale
- Shell
- Stelle
- 1.5k
- Fork
- 622
- Merge medio
- 6g 53m
- PR unite (30g)
- 9
Descrizione
I'm using the `docker-in-docker` feature to spin up some containers specific to a project, from within a dev container. I have two projects (frontend and backend) both in **separate** dev containers both using `docker-in-docker` and in both of them, I have a `docker-compose.yaml` file that defines how each service is run (there's databases etc).
```mermaid
flowchart LR
subgraph My Machine
A[VSCode]
end
A-->|SSH| B[VSCode Remote Host w/Docker]
B --> C["DevContainer (Frontend)
D-in-D
172.17.0.2"] --> C1["Container
(Frontend :3000)
172.18.0.2"]
B --> D["DevContainer (Backend)
D-in-D
172.17.0.3"] --> D1["Container
(Backend :8080)
172.18.0.2"]
D1--> D2[DB Container A]
D1--> D3[DB Container B]
```
How can I have the container running the frontend, get to the container running the backend (port 8080)? For context it's a Nuxt SSR application, so it has its own "server" process meaning the container (not my local browser) needs to see the backend.
I've tried `docker-outside-of-docker` but vscode seems to not care about the ports, and let me get to them locally (i.e. open my browser for the frontend) as they don't start "inside the devcontainer" so it can't see them. With `docker-in-docker`, the ports (3000 and 8080) are detected by VSCode, and I can get to them in my browser.
It seems that the devcontainer's IP address exposes the ports, which I can use in the child containers to directly reference the other devcontainer however this would require baking in some network config to the `devcontainer.json` which I'm attempting to avoid (might be unavoidable at this point). In the diagram above that is requesting `http://172.17.0.3:8080` from within the frontend container. Both child containers' networks seem isolated from each other (same IP, different container) but I can't seem to give them an IP on the `172.17.x.x` subnet. DNS resolution also doesn't work.
Thanks in advance 😄
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia leggendo la documentazione delle funzionalità docker-in-docker e docker-outside-of-docker, quindi esamina le due configurazioni devcontainer.json e i relativi file docker-compose.yaml. Riproduci le due configurazioni di rete annidate e verifica se i container riescono a risolvere o raggiungere l’altro devcontainer; il lavoro è completato quando il container frontend può raggiungere il backend sulla porta 8080 senza impostazioni di rete incorporate specifiche del progetto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- docker, docker-compose
- Ambito
- devops, networking
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100