Is it possible to enable networking between coder docker containers?
I am working on a mongod image. My ideal use case would be to have a coder template that creates and manages multiple mongodb databases that I can use in my other workspaces. I started creating a template with docker:
https://github.com/T0mThomson/coder-templates/tree/main/mongodb
It succesfully runs mongodb and a web ui to manage the databses (mongo-express).
However withouth manualy messing with the docker CLI in my terminal I can't automaticly get it to enable connection between other docker containers / workspaces in coder. I would like to expose the port
27017
in the default docker network OR enable networking between two coder workspaces, however I don't think that's possible yet?GitHub
coder-templates/mongodb at main · T0mThomson/coder-templates
Contribute to T0mThomson/coder-templates development by creating an account on GitHub.
19 Replies
I'm interested in doing something similar, but my basis is k8s. And with k8s, I believe you can set your app's (the one in the coder container) to the URL for the MongoDB service. I haven't gotten that far yet, but it should be relatively straight forward. Again, I'm definitely interested in any other solutions that there might be out there. 🙂
That was a really good hint. I edited my template and added a new app:
I set
share = "public"
so no authentification is required via coder.
When I open the app via http it looks like the mongodb server is responding:And I set
subdomain = true
so mongo connecotrs wouldn't be confused by the url.However I still couldn't manage to get it to connect to mongodb:
I tried no port (results in
27017
) 443
and 80
.No clue. What you are trying to do seems strange to me. Like, why would the coder URL offer a message from Mongo? And, why would you have an external URL to get to your MongoDB server? That is a basic no-no AFAIK.
Unless you are inside a personal network.
Looks like when you access your mongodb server via http protocol it sends you a response.
I wouldn't want to expose it to the public, but with port forward you would need to authentificate with your coder account. I don't think that would work.
I am testing solutions to make it work in my current coder setup.
Ok. What are you running it all on?
I am currently running coder on a single ubuntu server with docker containers as workspaces.
I'm not too fluent with Docker, but I believe when you start a pod, it should be automatically assigned an IP Address. This address is what your app in the coder workspace should be using to access MongodB. You can't use http to access mongo.
Yes thats possible, however you first need to configure the docker container to open the ports in the docker network.
I know that it's not possible to connect to mongodb via http.
However I wanted to show that the server should be accessible.
Maybe its not working because coder port forward only allows http(s) protocol and not others like
https://www.mongodb.com/docs/manual/reference/mongodb-wire-protocol/
So, you are trying to start a mongodb database inside a workspace? I'm confused. LOL! 😄 I would have imagined you'd start the Mongo server in its own container, before you create workspaces.
My thinking is, a workspace should only hold the app that needs to be worked on. Nothing else.
Correct, I am trying to create a template to run mongodb databases inside a workspace.
@Tom Thomson - Hmm... ok. I'm assuming your only using the workspace to access Terraform to build the container, right? Your intention isn't to actually develop in that container, right?
@Scott yes, correct
@Tom Thomson - I went looking yesterday, but closed the browser tab. At any rate, in the example templates there was one where Nginx was being added to the workspace. I'd say that is similar to what you need? I'd not try to add it in as the coder_app. All just a guess on my part though. 🙂
I found a solution where I created a new docker network using
docker network create coder
and then modified the template main.tf
and added the following config to the container resource:
This makes the docker container available in the docker network "coder" and sets a network alias to the workspace name so you can reach it easly withoud needing to retrieve the containers ip address (which can potentialy change on restart)Marked the thread as resolved.