#Is there an equivalent to `docker stop`?

1 messages · Page 1 of 1 (latest)

bitter geyser
#

I am looking to create a database container which gets modified, so I have it currently successfully receive the migrations and everything seems fine; but I am unable to publish it, because it is running a foreground job. Is there a way to force a running command to stop, currently I am using docker stop, but I can't seem to find a way to do that in dagger.

Thanks

vernal stump
#

Hey @royal meteor , How would you handle that with the current service API?
Load a DB as a service, migrate the schema/data via another part of the CI, then stop the DB service and publish the container once modified. (also, would that work as the data might surely be saved as some kind of volume mount?)

royal meteor
#

The tricky thing here will be dealing with the 10 second grace period for shutting down a service - that's assuming you're using services here, which might not be necessary.

You could always run the container yourself and use its hostname/endpoint directly to connect to it, and then interrupt it when you're done with it. This should feel pretty intuitive in Go with context.Context but I'm not sure about other SDKs:

ctx := context.Background()
client, _ := dagger.Connect(ctx)

db := client.Container().From("postgres").WithExec(nil)

hostname, _ := db.Hostname(ctx)

cancelCtx, cancel := context.WithCancel(ctx)
go db.ExitCode(cancelCtx)

migrate := client.Container().From("foo").WithExec([]string{"migrate", "--host", hostname})
_, _ = migrate.ExitCode(cancelCtx)
cancel()

// ... code/commands to run after stopping ...
#

note that stopping is async, if that matters. it should stop pretty quickly though (it gets a kill -9)

vernal stump
#

Wouldn't getting a kill -9 corrupt the db files, though?

royal meteor
#

it could, yeah; hard to say whether that matters in this case though (not enough context)