#Long-lived container(s) with dagger
1 messages · Page 1 of 1 (latest)
I want to do this as well, I'm currently working on it but have the same unknowns.
what SDK are you using? I'm using Go most likely
I just started, I am going to look at the node and python ones now
I have a tool in Go already, which I may wish to bake some of this into, so I may still stay with Go
I think it ought to be possible to do what you want, with exec, but not sure if you can run and walk away yet, like docker-compose up
is there API that would fill the docker-compose down side?
Yes Dagger is designed to make this possible. There are a few features missing for a great experience, but you can get it to work with a few workarounds
The main missing feature is host-to-container networking.
See #1120843832892870696 for a recent discussion
In particular, here's an example of the workarounds in action: https://github.com/vito/dagger-compose
(also a really fun project 🙂
I believe is uses an unofficial patch of the Dagger Engine for host-to-container networking though, so pretty extreme
yeah, just saw that
A less radical workaround, that works with the stable Dagger Engine, is to rely on host-to-container unix socket mounting (which works today), and proxy tcp->unix on the host, and unix->tcp in a container
so better support is on the roadmap it sounds like?
As a describe it in the other discussion:
postgres client on host --> socat on host ----- (unix socket) ---> socat in container --> postgres in container
Yes 100%. It's not even a huge lift to implement. It's been at the API bikeshedding stage, and we all got busy with other things. But it's been several requests about this feature in the last couple weeks... Time for us to re-prioritize it I think
For context on the container networking saga: https://github.com/dagger/dagger/issues/4080
it would unlock a use-case for use, would probably want both sync & async modes (i.e. docker run [-d])
or I suppose being able to life-cycle containers
Yeah we've discussed that... Worth opening an issue for that sync mode. There are UX subtleties (so far every Dagger user shares the universal expectation that run is supposed to return). But nothing a good bikeshedding session can't fix.
ok, keep me up to date on that development. I think I will use something different for this use-case for now until the hostnetworking is supported but just in case someone stumples upon this, here's a quick n dirty example I wrote that spins up 2 containers and keeps them running (no hostnetworking tho) - apparently one needs to await the exitCode to keep the container alive.
import Client, { connect } from "@dagger.io/dagger";
// initialize Dagger client
connect(
async (client: Client) => {
const db = client
.container()
.from("postgres")
.withEnvVariable("POSTGRES_PASSWORD", "mysecretpassword")
.withExposedPort(5432);
const webServer = client
.container()
.from("node:18")
.withExec(["node", "-e", "console.log('starting fake webserver'); setTimeout(() => {}, 10000000)"])
.withExposedPort(8080);
await Promise.all([db.exitCode(), webServer.exitCode()]);
},
{ LogOutput: process.stderr }
);
There is a new call sync() which you can use to force execution without having to query the exit code
does that alleviate the need for the CACHE=time.Now() business?
my hunch is they are two sides of the same coin
sync at the end, cache bust in the middle
they are orthogonal , Sync forces evaluation by the engine, but caching happens normally