Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker-in-docker allow two devcontainers' sub-containers to speak #1135

Open
napei opened this issue Oct 1, 2024 · 0 comments
Open

Docker-in-docker allow two devcontainers' sub-containers to speak #1135

napei opened this issue Oct 1, 2024 · 0 comments

Comments

@napei
Copy link

napei commented Oct 1, 2024

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).

flowchart LR
    subgraph My Machine
    A[VSCode]
    end

    A-->|SSH| B[VSCode Remote Host w/Docker]
    B --> C["DevContainer (Frontend)<br>D-in-D<br>172.17.0.2"] --> C1["Container<br>(Frontend :3000)<br>172.18.0.2"]

    B --> D["DevContainer (Backend)<br>D-in-D<br>172.17.0.3"] --> D1["Container<br>(Backend :8080)<br>172.18.0.2"]
    D1--> D2[DB Container A]
    D1--> D3[DB Container B]
Loading

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 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant