#How do I publish an image locally?
1 messages Β· Page 1 of 1 (latest)
do you want to export it to your local filesystem, or a locally running registry, or a locally running docker engine?
local docker engine (OrbStack in my case)
I want to use the built image with Docker Compose
@slim sluice from Dagger's point of view, your local docker/orbstack is just another local service running on your host. So you should approach it like any other client/server situation in your workflow, like for example if you were connecting to a DB running on your host
In the case of docker that means:
- Passing your host's docker unix socket as an argument to a function
- Running a docker client in a container with that unix socket mounted
There are a bunch of Dagger modules that do that
@novel portal @wild peak @ripe sparrow @knotty crow what docker module would you recommend? π
I know mine doesn't support external engines (I should add that...)
Would that require me to switch to a Dockerfile for the image? Or can I still build it with dag.container() ...?
you can still build it with Dagger. The main difference is that your function will require the docker socket or a TCP endpoint service so you can push to it
Okay I think this makes sense. I can try later. Would love examples if anyone has some!
1 sec
here's a rough of example on how you can achieve it @slim sluice
func (m *Lala) Test(
ctx context.Context,
docker *dagger.Socket,
) {
c := dag.Container().From("alpine")
dockerCli := dag.Container().From("docker:cli").WithUnixSocket("/var/run/docker.sock", docker).
WithMountedFile("image.tar", c.AsTarball())
out, _ := dockerCli.WithExec([]string{"docker", "load", "-i", "image.tar"}).Stdout(ctx)
image := strings.TrimSpace(strings.SplitN(out, ":", 2)[1])
dockerCli.WithExec([]string{"docker", "tag", image, "mycustomimg"}).Sync(ctx)
}
This is super helpful, thank you!! this is the last thing I need to complete my monorepo migration from Earthly
Here's my module if it helps: https://daggerverse.dev/mod/github.com/shykes/x/docker
If only to take inspiration and copy-paste π
Ah man, it actually does support external engines, but you need to make it a Service type. And at the moment that type only supports TCP and UDP endpoints, not unix sockets
@slim sluice I figured out how to use my module the way you need it π