Created
September 20, 2020 07:41
-
-
Save lynzrand/59b3ef618a5d96965b0db12730cb7c33 to your computer and use it in GitHub Desktop.
Bollard build image result issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [package] | |
| authors = ["Rynco Maekawa <[email protected]>"] | |
| edition = "2018" | |
| name = "docker-api" | |
| version = "0.1.0" | |
| # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
| [dependencies] | |
| bollard = "0.8.0" | |
| futures = "*" | |
| hyper = {version = "0.13.7", features = ["stream"]} | |
| tar = "*" | |
| tokio = {version = "0.2.22", features = [ | |
| "time", | |
| "io-util", | |
| "process", | |
| "stream", | |
| "rt-threaded", | |
| "macros", | |
| ]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Shared Volume | |
| FROM busybox:buildroot-2014.02 | |
| VOLUME /data | |
| CMD ["/bin/sh"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use bollard::{image::BuildImageOptions, Docker}; | |
| use futures::stream::StreamExt; | |
| #[tokio::main] | |
| async fn main() { | |
| let docker = Docker::connect_with_local_defaults().unwrap(); | |
| let mut tarball = Vec::new(); | |
| let mut builder = tar::Builder::new(&mut tarball); | |
| builder | |
| .append_file( | |
| "Dockerfile", | |
| &mut std::fs::File::open("Dockerfile").unwrap(), | |
| ) | |
| .unwrap(); | |
| builder.finish().unwrap(); | |
| drop(builder); | |
| docker | |
| .build_image( | |
| BuildImageOptions { | |
| dockerfile: "Dockerfile", | |
| t: "test:test", | |
| ..Default::default() | |
| }, | |
| None, | |
| Some(tarball.into()), | |
| ) | |
| .for_each(|x| async move { println!("{:?}", x) }) | |
| .await; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {"stream":"Step 1/3 : FROM busybox:buildroot-2014.02"} | |
| {"stream":"\n"} | |
| {"stream":" ---\u003e 9875fb006e07\n"} | |
| {"stream":"Step 2/3 : VOLUME /data"} | |
| {"stream":"\n"} | |
| {"stream":" ---\u003e Using cache\n"} | |
| {"stream":" ---\u003e 9d806142a52c\n"} | |
| {"stream":"Step 3/3 : CMD [\"/bin/sh\"]"} | |
| {"stream":"\n"} | |
| {"stream":" ---\u003e Using cache\n"} | |
| {"stream":" ---\u003e f95df1e61acc\n"} | |
| {"aux":{"ID":"sha256:f95df1e61accc87736b6625495179e07d3e19b31f35691c5e57d84cefcbe4623"}} | |
| {"stream":"Successfully built f95df1e61acc\n"} | |
| {"stream":"Successfully tagged test:test\n"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Compiling docker-api v0.1.0 (D:\Projects\test\docker-api) | |
| Finished dev [unoptimized + debuginfo] target(s) in 10.26s | |
| Running `target\debug\docker-api.exe` | |
| Ok(CreateImageInfo { id: None, error: None, status: None, progress: None, progress_detail: None }) | |
| Ok(CreateImageInfo { id: None, error: None, status: None, progress: None, progress_detail: None }) | |
| Ok(CreateImageInfo { id: None, error: None, status: None, progress: None, progress_detail: None }) | |
| Ok(CreateImageInfo { id: None, error: None, status: None, progress: None, progress_detail: None }) | |
| Ok(CreateImageInfo { id: None, error: None, status: None, progress: None, progress_detail: None }) | |
| Ok(CreateImageInfo { id: None, error: None, status: None, progress: None, progress_detail: None }) | |
| Ok(CreateImageInfo { id: None, error: None, status: None, progress: None, progress_detail: None }) | |
| Ok(CreateImageInfo { id: None, error: None, status: None, progress: None, progress_detail: None }) | |
| Ok(CreateImageInfo { id: None, error: None, status: None, progress: None, progress_detail: None }) | |
| Ok(CreateImageInfo { id: None, error: None, status: None, progress: None, progress_detail: None }) | |
| Ok(CreateImageInfo { id: None, error: None, status: None, progress: None, progress_detail: None }) | |
| Ok(CreateImageInfo { id: None, error: None, status: None, progress: None, progress_detail: None }) | |
| Ok(CreateImageInfo { id: None, error: None, status: None, progress: None, progress_detail: None }) | |
| Ok(CreateImageInfo { id: None, error: None, status: None, progress: None, progress_detail: None }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from io import BytesIO | |
| from docker import APIClient | |
| dockerfile = ''' | |
| # Shared Volume | |
| FROM busybox:buildroot-2014.02 | |
| VOLUME /data | |
| CMD ["/bin/sh"] | |
| ''' | |
| f = BytesIO(dockerfile.encode("utf8")) | |
| cli = APIClient() | |
| resp = cli.build(fileobj=f, rm=True, tag="test:test") | |
| print("\n".join([line.decode("utf8") for line in resp])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment