I’m trying to connect to a database that is exposed at localhost on my machine but I don’t know how waypoint 's networking is setup so I can’t reach it from my app.
Are you deploying your app to a platform like Docker that is also on the same workstation as your database?
Normally in that case I would expect that you would bind your localhost port to a container port when running a command like docker run
. The Docker plugin does not currently enable specifying the equivalent of docker run -p 127.0.0.1:3306:3306/tcp
.
There are several possible work-arounds:
- Probably by far the easiest, use something like ngrok to expose your local database port with a URL that is reachable from inside the docker container.
- You could using the Waypoint
exec
plugin rather than your platform plugin to calldocker
with the arguments that wire in your localhost database port into the container. That might look something like this if it were mysql listening on 3306:
deploy {
use "exec" {
command = ["docker", "run", "-p", "127.0.0.1:3306:3306/tcp", "-p", "127.0.0.1:3000:3000/tcp", "{{.Input.DockerImageFull}}", "/path/to/start/command"]
}
}
There is kubernetes example with the exec
plugin that could be adapted to do something like this: https://github.com/hashicorp/waypoint-examples/tree/main/kubernetes/exec-kubectl-apply
Notably if you don’t set the env variables as show in the kubernetes example, then the Entrypoint will not be able to call back into the Waypoint Server and Waypoint URL Service, so logs, exec, and preview URLs would not work.
Yes I am using the docker platform and my database which is also in a container has a port exposed on my host.
0.0.0.0:5432->5432/tcp