Docker in Docker setup, reach services in outer docker network

Hi there, relatively new to Coder. I'm running Coder as a service in my Docker Swarm. Alongside Coder I also host a database I want to use for testing purposes. How do I connect to this database (that's running in the same network as the coder server) from my workspace? I can connect to databases that are publicly accessible through the internet and I can connect to databases hosted within my workspace container, but I can't figure out how to access services running on the "outer" docker network.
9 Replies
Deleted User
Deleted User2y ago
I even tried to visualize it in paint if that helps 😉
No description
Deleted User
Deleted User2y ago
please @ me when replying
Geoff
Geoff2y ago
@Deleted User the answer you seek is heavily dependent on your networking configuration. Workspaces created by Coder need network connectivity to the Coder instance. When a workspace boots it heads to coder.example.com/bin and downloads the agent. Then launches the agent on the workspace/registers itself with Coder. At that point Workspace is accessible to authenticated users regardless of the network you are on as Coder Portal+Workspaces+Coder Console uses tailscale/wireguard under the hood. For network connectivity between your workspace and your database you will need network connectivity between them. You could achieve this though routing, nat, opening firewalls, configuring vpns, installing tailscale/wireguard in the workspace+database.
Deleted User
Deleted User2y ago
Alright that helps a lot, thanks for explaining Now I'm not too familiar with tailscale/wireguard but in essence, coder is creating a virtual network for the workspace which makes it impossible to directly reach outer layers of my docker setup, correct? so I'd have to set something up that allows this workspace network to communicate with my docker network, although coder is running inside the docker network
Geoff
Geoff2y ago
which makes it impossible to directly reach outer layers of my docker setup, correct
No.
coder is creating a virtual network for the workspace
Yes
Deleted User
Deleted User2y ago
I found out my lack of knowledge about terraform was causing all of this. Read more into how terraform works and got it working. Thanks a lot for your help though! You can consider this solved 👍 If anyone else is finding this post in the future: I didn't realise that with the starter template using docker_image, it would not attach the container to my network but only run it locally on the server. Swapped it out for a docker_service resource and that did the trick. Kind of obvious in hindsight but that's how it goes sometimes 😄 https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources/service
Geoff
Geoff2y ago
can you share up a redacted gist of your template? Maybe there's something I can do here to make our docs better for others.
Deleted User
Deleted User2y ago
Gist
coder-swarm-workspace.tf
GitHub Gist: instantly share code, notes, and snippets.
Deleted User
Deleted User2y ago
again, doesn't have much to do with coder and more about how to use terraform properly, but maybe that helps other people looking into hosting workspaces in a docker swarm
Want results from more Discord servers?
Add your server