#Run existing Docker images

1 messages · Page 1 of 1 (latest)

hybrid wagon
#

Hey there!

I'm looking to lint my Docker file with hadolint. They provide an already built Docker image that you can run with this command docker run --rm -i hadolint/hadolint < Dockerfile.

I couldn't figure out an easy way to do with the Go SDK.

More info on hadolint here https://github.com/hadolint/hadolint/tree/master/docker.

Much appreciated!

velvet narwhal
#

👋 Here's one approach. Copy the binary from one container into another one with a shell and you're good to go! Simpler, just mount your host directory with the Dockerfile in it and go! lol

package main

import (
    "context"
    "os"
    "time"

    "dagger.io/dagger"
)

func main() {
    ctx := context.Background()
    client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout))
    if err != nil {
        panic(err)
    }
    // get project dir with Dockerfile inside
    src := client.Host().Directory(".")

    hadolint := client.
        Container().
        From("hadolint/hadolint").
        WithMountedDirectory("/src", src).
        // ensure lint step is not cached (just so we can observe it)
        WithEnvVariable("NO_CACHE", time.Now().String()).
        WithExec([]string{"/bin/hadolint", "/src/Dockerfile"})

    _, err = hadolint.ExitCode(ctx)

    if err != nil {
        panic(err)
    }
}
fading jungle
#

@velvet narwhal why not just running the hadolint container directly on Dagger? Just thinking why copying the binary is necessary 🤔

velvet narwhal
#

could have overthought it late last night 😆, so in that case, mount the src to the hadolint container right?

#

Ah, yes. Got to work just fine. Lol. Will change example above.