#Using COPY --from with the Go SDK

1 messages · Page 1 of 1 (latest)

dull kraken
#

I'm trying to using the COPY --from command to get a directory from an image that is not part of the multi-stage build. in Dagger.

Here is an example snippet from a Dockerfile:

FROM vendor/image
COPY --from=another-vendor/another-image /opt/vendor-deps /opt/vendor-deps

Is there an equivalent way to perform this in the Go SDK?

high heart
#

Yes, you can definitely do that. Let me find a few pointers for you

topaz escarp
#

@dull kraken you can use the Container().From("address"). step to get whatever directory or file from other container. Here's an example:

package main

import (
    "context"
    "fmt"

    "dagger.io/dagger"
)

func main() {
    c, err := dagger.Connect(context.Background())
    if err != nil {
        panic(err)
    }
    defer c.Close()

    ctx := context.Background()

    helloDir := c.Container().From("hello-world").Directory("/")

    out, err := c.Container().From("alpine").
        WithDirectory("/hello", helloDir).
        WithExec([]string{"/hello/hello"}).Stdout(ctx)

    fmt.Println(out, err)
}