fussybeaver / bollard

Docker daemon API in Rust
Apache License 2.0
911 stars 134 forks source link

Building an image using a local Dockerfile #367

Closed bpmooch closed 10 months ago

bpmooch commented 10 months ago

https://github.com/fussybeaver/bollard/blob/master/examples/build.rs

I am attempting to build an image using a local dockerfile:

        let dockerfile = test_dockerfile!("Dockerfile.minio");
        eprintln!("{dockerfile}");
        let build_image_options = BuildImageOptions {
            dockerfile,
            t: MINIO_IMAGE,
            nocache: true,
            rm: true,
            ..Default::default()
        };
        let mut image_build_stream = docker.build_image(build_image_options, None, None);
        while let Some(msg) = image_build_stream.try_next().await? {
            println!("Message: {msg:?}");
        }

I get an error from this code saying DockerResponseServerError { status_code: 500, message: "Cannot locate spec ified Dockerfile: /Users/mooch/p/sra/sherpa/api/resources/dockerfiles/Dockerfile.minio" } but I am sure the file is in the correct place. I noticed in the example, a remote file is used. Is there something I'm missing about building a docker image from a local dockerfile?

bpmooch commented 10 months ago

I figured out the solution for this creating a tarball with the Dockerfile inside and using that as docker context for the build.

fussybeaver commented 10 months ago

Yeah, that's the correct way to upload a Dockerfile with the HTTP API... There is a more advanced mechanism using the new buildkit features and a GRPC interface, but I've yet to make an example / test case to show it works.