#How do I publish an image locally?

1 messages Β· Page 1 of 1 (latest)

slim sluice
#

I have an Earthfile that I use to build an image that's only used locally. Is it possible to export a local OCI image with Dagger? I tried searching docs/discord but it's still unclear to me.

west kiln
slim sluice
#

local docker engine (OrbStack in my case)

#

I want to use the built image with Docker Compose

west kiln
#

@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...)

slim sluice
#

Would that require me to switch to a Dockerfile for the image? Or can I still build it with dag.container() ...?

long sinew
slim sluice
#

Okay I think this makes sense. I can try later. Would love examples if anyone has some!

long sinew
#

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)
}
slim sluice
#

This is super helpful, thank you!! this is the last thing I need to complete my monorepo migration from Earthly

west kiln
#

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

west kiln
#

@slim sluice I figured out how to use my module the way you need it πŸ™‚