vv9k / docker-api-rs Goto Github PK
View Code? Open in Web Editor NEWRust interface to Docker containers
License: MIT License
Rust interface to Docker containers
License: MIT License
docker version
on the command line:Client:
Cloud integration: v1.0.29
Version: 20.10.17
API version: 1.41
Go version: go1.17.11
Git commit: 100c701
Built: Mon Jun 6 23:04:45 2022
OS/Arch: darwin/arm64
Context: default
Experimental: true
Server: Docker Desktop 4.12.0 (85629)
Engine:
Version: 20.10.17
API version: 1.41 (minimum version 1.12)
Go version: go1.17.11
Git commit: a89b842
Built: Mon Jun 6 23:01:01 2022
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.6.8
GitCommit: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
runc:
Version: 1.1.4
GitCommit: v1.1.4-0-g5fd4c4d
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Creating a container and attaching stdin, stdout & stderr works perfectly fine but after setting .tty(true)
in ContainerCreateOpts
no output from stdout and stderr is received.
use docker_api::{Docker, opts::ContainerCreateOpts};
use futures_util::StreamExt;
#[tokio::main]
async fn main() {
let docker = Docker::new("unix:///var/run/docker.sock").unwrap();
// First run `docker pull chentex/random-logger`
let container = docker.containers().create(&ContainerCreateOpts::builder()
.attach_stdout(true)
.attach_stdin(true)
.attach_stderr(true)
.tty(false)
.image("chentex/random-logger")
.auto_remove(true)
.build()
).await.unwrap();
println!("Created container: {}", container.id());
println!("Starting container...");
container.start().await.unwrap();
println!("Started container.");
let mut multiplexer = container.attach().await.unwrap();
while let Some(next) = multiplexer.next().await {
let chunk = next.unwrap();
println!("{chunk:?}");
}
}
Works as expected. Output is printed to console.
After changing .tty(false)
to .tty(true)
(like the following) no output is printed:
use docker_api::{Docker, opts::ContainerCreateOpts};
use futures_util::StreamExt;
#[tokio::main]
async fn main() {
let docker = Docker::new("unix:///var/run/docker.sock").unwrap();
// First run `docker pull chentex/random-logger`
let container = docker.containers().create(&ContainerCreateOpts::builder()
.attach_stdout(true)
.attach_stdin(true)
.attach_stderr(true)
.tty(true)
.image("chentex/random-logger")
.auto_remove(true)
.build()
).await.unwrap();
println!("Created container: {}", container.id());
println!("Starting container...");
container.start().await.unwrap();
println!("Started container.");
let mut multiplexer = container.attach().await.unwrap();
while let Some(next) = multiplexer.next().await {
let chunk = next.unwrap();
println!("{chunk:?}");
}
}
Issue: No output is printed to stdout.
In both scenarios I manually checked the logs of the container and they were filled with log messages.
Edit: Improved code formatting.
docker version
on the command line:Client: Docker Engine - Community
Cloud integration: 1.0.12
Version: 20.10.5
API version: 1.41
Go version: go1.13.15
Git commit: 55c4c88
Built: Tue Mar 2 20:13:00 2021
OS/Arch: darwin/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.5
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: 363e9a8
Built: Tue Mar 2 20:15:47 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.4
GitCommit: 05f951a3781f4f2c1911b05e61c160e9c30eaa8e
runc:
Version: 1.0.0-rc93
GitCommit: 12644e614e25b05da6fd08a38ffa0cfe1903fdec
docker-init:
Version: 0.19.0
GitCommit: de40ad0
When pulling an image, per the example in the repository, the image is able to be pulled successfully per the logs, but then the program just hangs, without moving out of the loop, at the end. Is there a way to close the stream or send None when the pull has finished?
let pull_opts = PullOpts::builder().image(config.image.clone()).build();
let images = docker.images();
let mut stream = images.pull(&pull_opts);
while let Some(pull_result) = stream.next().await {
match pull_result {
Ok(output) => {
println!("{:?}", output);
},
Err(e) => eprintln!("{}", e),
}
}
futures_codec is unmaintained and pulls in outdated versions of bytes
and pin-project
https://deps.rs/crate/futures_codec/0.4.1
I propose that we swap futures_codec with tokio_util (I'm not sure of the exact history here but it seems one was copied into the other at some point because they have the same API)
futures_codec is async runtime agnostic, so if we planned to make docker-api async runtime agnostic as well then using tokio_util would be a misstep. But currently docker-api does use tokio making docker-api tokio specific.
I would be happy to provide a PR to perform this change (here and in container-api), but wanted to check in first to see if this was the right direction.
master
@ 6c0a8f4I believe that Container::exec
shouldn't tie the lifetime of &self
to 'docker
, but rather Container
should have a generic lifetime that would let you tie the 'docker
lifetime to self.docker
itself.
From looking at the implementation, I think the current way isn't required and probably wasn't the intent based on the name of the lifetime.
(Though, I am getting a bit lost in all the macros that actually generate the types. I may be missing a reason why it has to be this way.)
I'm trying to use Container::exec
within a function in my library and I want to return the Multiplexer
it gives me. However, the lifetime of the Multiplexer
is getting tied to the Container
struct.
A simplified example:
pub async fn shell(&self, container_id: &str) -> Result<Multiplexer> {
trace!(container_id, "attach to container");
let mut container = self.client.containers().get(container_id);
let create_opts = ExecCreateOpts::builder()
.attach_stdout(true)
.attach_stderr(true)
.attach_stdin(true)
.detach_keys("ctrl-d")
.tty(true)
.command(["/bin/sh"])
.build();
let start_opts = ExecStartOpts::builder().tty(true).build();
let io = container.exec(&create_opts, &start_opts).await?;
Ok(io)
}
gives
error[E0515]: cannot return value referencing local variable `container`
--> conductor/src/containers/mod.rs:819:17
|
817 | let io = container.exec(&create_opts, &start_opts).await?;
| ----------------------------------------- `container` is borrowed here
818 |
819 | Ok(io)
| ^^^^^^ returns a value referencing data owned by the current function
Hey there! Was checking out the example for exec and I see it returns a stream with chunks of stdout, stderr, and stdin.
Two questions:
For example, if I used exec to start a /bin/sh process in my container with tty enabled, how would I write to its stdin?
Thanks for putting this crate together! Hoping to use it for chipsenkbeil/distant#194
I have been trying to add stop and start commands, but no luck so far. Can someone provide an example of how to do this?
docker version
on the command line:Client: Docker Engine - Community
Version: 20.10.7
API version: 1.41
Go version: go1.13.15
Git commit: f0df350
Built: Wed Jun 2 11:56:47 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.7
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: b0f5bc3
Built: Wed Jun 2 11:54:58 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.6
GitCommit: d71fcd7d8303cbf684402823e425e9dd2e99285d
runc:
Version: 1.0.0-rc95
GitCommit: b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
docker-init:
Version: 0.19.0
GitCommit: de40ad0
I am trying to build a pkger recipe. The following is the output from RUST_LOG=docker_api=trace,pkger=trace pkger build decide.rs
. (The logs from before the broken message are in the details tag.)
TRACE got chunk b"{"stream":" ---\u003e 9ffc72f820e7\n"}\r\n", log.target="docker_api::docker", log.module_path="docker_api::docker", log.file="/home/melizalab/.cargo/git/checkouts/docker-api-rs-9127327c5ec9cacd/8126914/src/docker.rs", log.line=308
INFO ---> 9ffc72f820e7
TRACE got chunk b"{"aux":{"ID":"sha256:9ffc72f820e7826fc4939b458fcbe9945f17ca8032e9afe638a3bc6a0a90ca0e"}}\r\n", log.target="docker_api::docker", log.module_path="docker_api::docker", log.file="/home/melizalab/.cargo/git/checkouts/docker-api-rs-9127327c5ec9cacd/8126914/src/docker.rs", log.line=308
TRACE sending request POST unix://2f72756e2f646f636b65722e736f636b:0/v1.41/containers/create, log.target="docker_api::conn::transport", log.module_path="docker_api::conn::transport", log.file="/home/melizalab/.cargo/git/checkouts/docker-api-rs-9127327c5ec9cacd/8126914/src/conn/transport.rs", log.line=357
TRACE got response 201 Created {"api-version": "1.41", "content-type": "application/json", "docker-experimental": "false", "ostype": "linux", "server": "Docker/20.10.7 (linux)", "date": "Sat, 17 Jul 2021 23:16:17 GMT", "content-length": "88"}, log.target="docker_api::conn::transport", log.module_path="docker_api::conn::transport", log.file="/home/melizalab/.cargo/git/checkouts/docker-api-rs-9127327c5ec9cacd/8126914/src/conn/transport.rs", log.line=237
TRACE {"Id":"fb213ca2762463acbbb658acdb0c4356bfe5bdc8aae80d21ef7e16d86e537ff7","Warnings":[]}
, log.target="docker_api::docker", log.module_path="docker_api::docker", log.file="/home/melizalab/.cargo/git/checkouts/docker-api-rs-9127327c5ec9cacd/8126914/src/docker.rs", log.line=216
INFO created container, id=fb213ca27624
TRACE sending request POST unix://2f72756e2f646f636b65722e736f636b:0/v1.41/containers/fb213ca2762463acbbb658acdb0c4356bfe5bdc8aae80d21ef7e16d86e537ff7/start, log.target="docker_api::conn::transport", log.module_path="docker_api::conn::transport", log.file="/home/melizalab/.cargo/git/checkouts/docker-api-rs-9127327c5ec9cacd/8126914/src/conn/transport.rs", log.line=357
TRACE got response 204 No Content {"api-version": "1.41", "docker-experimental": "false", "ostype": "linux", "server": "Docker/20.10.7 (linux)", "date": "Sat, 17 Jul 2021 23:16:18 GMT"}, log.target="docker_api::conn::transport", log.module_path="docker_api::conn::transport", log.file="/home/melizalab/.cargo/git/checkouts/docker-api-rs-9127327c5ec9cacd/8126914/src/conn/transport.rs", log.line=237
INFO started container, id=fb213ca27624
TRACE stdout=true, stderr=true
INFO collecting output
TRACE sending request GET unix://2f72756e2f646f636b65722e736f636b:0/v1.41/containers/fb213ca2762463acbbb658acdb0c4356bfe5bdc8aae80d21ef7e16d86e537ff7/logs?stderr=true&stdout=true, log.target="docker_api::conn::transport", log.module_path="docker_api::conn::transport", log.file="/home/melizalab/.cargo/git/checkouts/docker-api-rs-9127327c5ec9cacd/8126914/src/conn/transport.rs", log.line=357
TRACE got response 200 OK {"api-version": "1.41", "docker-experimental": "false", "ostype": "linux", "server": "Docker/20.10.7 (linux)", "date": "Sat, 17 Jul 2021 23:16:18 GMT", "transfer-encoding": "chunked"}, log.target="docker_api::conn::transport", log.module_path="docker_api::conn::transport", log.file="/home/melizalab/.cargo/git/checkouts/docker-api-rs-9127327c5ec9cacd/8126914/src/conn/transport.rs", log.line=237
TRACE stderr=
TRACE stdout=PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
DEBUG parsed image info, os=Os {
distribution: Debian,
version: Some(
"11",
),
}
TRACE sending request GET unix://2f72756e2f646f636b65722e736f636b:0/v1.41/images/sha256:9ffc72f820e7826fc4939b458fcbe9945f17ca8032e9afe638a3bc6a0a90ca0e/json, log.target="docker_api::conn::transport", log.module_path="docker_api::conn::transport", log.file="/home/melizalab/.cargo/git/checkouts/docker-api-rs-9127327c5ec9cacd/8126914/src/conn/transport.rs", log.line=357
TRACE got response 200 OK {"api-version": "1.41", "content-type": "application/json", "docker-experimental": "false", "ostype": "linux", "server": "Docker/20.10.7 (linux)", "date": "Sat, 17 Jul 2021 23:16:18 GMT", "transfer-encoding": "chunked"}, log.target="docker_api::conn::transport", log.module_path="docker_api::conn::transport", log.file="/home/melizalab/.cargo/git/checkouts/docker-api-rs-9127327c5ec9cacd/8126914/src/conn/transport.rs", log.line=237
It seems like the problem is that the Cmd
field has a value of "null", but I don't understand the structure of the code enough to know where that might have come from.
In the docker reference page they outline the ability to pass in a path to a dockerfile using --file
. So from the command line we can run something like:
docker build -t <tag-name> -f <path-to-docker-file> <path-to-context>
I can't seem to find this functionality or the equivalent implementation. Also could have totally just missed it.
I would love to utilize this functionality since I have a Dockerfile in a large repository and Images::build()
and Images::build_par()
are too slow. So would love to have a Dockerfile in its own directory within the large repo and build an image as I can through the command line like:
docker build -t <tag-name> -f <large-repo/dockerfile-repo/Dockerfile> <large-repo>
Does this functionality exist? Or is there an equivalent way of doing this? Once again, I may have missed it in the docs/code, so my apologies if that is the case!
Thank you!
The following program does not end because the cat
is waiting for stdin forever:
use docker_api::{api::ContainerCreateOpts, Docker};
use futures_util::AsyncWriteExt;
use std::env;
#[tokio::main]
async fn main() {
let uri: String = env::var("DOCKER_HOST").unwrap_or("unix:///var/run/docker.sock".to_string());
let docker = Docker::new(uri).unwrap();
let opts = ContainerCreateOpts::builder("alpine")
.cmd(["sh", "-c", "cat>a"])
.attach_stdin(true)
.build();
let container = docker.containers().create(&opts).await.unwrap();
let mut m = container.attach().await.unwrap();
container.start().await.unwrap();
let mut text = &b"input"[..];
m.write_all(&mut text).await.unwrap();
m.close().await.unwrap();
container.wait().await.unwrap();
}
Multiplexer::close
should send EOF to cat
.
docker version
on the command line: Client:Docker Engine - Community
Version: 20.10.13
API version: 1.41
Go version: go1.16.15
Git commit: a224086
Built: Thu Mar 10 14:08:23 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.13
API version: 1.41 (minimum version 1.12)
Go version: go1.16.15
Git commit: 906f57f
Built: Thu Mar 10 14:06:09 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.5.10
GitCommit: 2a1d4dbdb2a1030dc5b01e96fb110a9d9f150ecc
runc:
Version: 1.0.3
GitCommit: v1.0.3-0-gf46b6ba
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Crate version:
master head
OS:
Windows 11
Output of running docker version
on the command line:
Client:
Cloud integration: 1.0.17
Version: 20.10.7
API version: 1.41
Go version: go1.16.4
Git commit: f0df350
Built: Wed Jun 2 12:00:56 2021
OS/Arch: windows/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.7
API version: 1.41 (minimum version 1.12)
Go version: go1.13.15
Git commit: b0f5bc3
Built: Wed Jun 2 11:54:58 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.6
GitCommit: d71fcd7d8303cbf684402823e425e9dd2e99285d
runc:
Version: 1.0.0-rc95
GitCommit: b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Greetings,
After looking into source code, docs.rs documentation for this crate and code editor autocomplete I couldn’t find a way to connect a container to a network during creation (as with the --network
flag).
Have I missed this or is this actually not implemented yet?
docker version
on the command line:
In docker api version 1.41, /container/create
's name argument should pass by Query Parameters
see https://docs.docker.com/engine/api/v1.41/#operation/ContainerCreate
All functionality exposed as a public API should be tested
I am trying to use some docker library to write tests. There looks 3 choices in the crates.io: shiplift, bollard and docker-api.
I tried shiplift first because it is best starred but after all I noticed it is unmaintained.
Then look into this library now and notice the APIs are much similar to shiplift. Question 1: Is this a fork?
Question 2 is about comparison with the alternative bollard. What is the strong point of this library against bollard?
Hello, thank you for creating this library, enjoying it a lot.
But there's a problem I couldn't quite figure out how to solve:
Let's say I have a running container which I attached using .attach()
, which streams some stdout, then I want to make a separate exec (docker exec -it /bin/sh) to work with this container in a separate tab, but seems like I could't do it because container.exec()
returns only output and doesn't have an option to accept input.
I'd like to propose adding the ability to use attach for execs, or provide stdin handle for execs.
I would like to hear your thoughts on this, thank you.
With "docker-api = { version = "*" }" in Cargo.toml of my project, cargo build
gives
>cargo build
Updating crates.io index
Compiling docker-api v0.5.1
error[E0432]: unresolved import `futures_util::Stream`
--> /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/docker-api-0.5.1/src/api/container/mod.rs:12:5
|
12 | Stream, TryStreamExt,
| ^^^^^^
| |
| no `Stream` in the root
| help: a similar name exists in the module (notice the capitalization): `stream`
error[E0432]: unresolved import `futures_util::Stream`
--> /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/docker-api-0.5.1/src/api/system/mod.rs:9:20
|
9 | use futures_util::{Stream, TryStreamExt};
| ^^^^^^
| |
| no `Stream` in the root
| help: a similar name exists in the module (notice the capitalization): `stream`
error[E0405]: cannot find trait `Stream` in crate `futures_util`
--> /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/docker-api-0.5.1/src/builder.rs:539:33
|
539 | ) -> impl futures_util::Stream<Item = crate::Result<crate::conn::TtyChunk>> + Unpin + 'docker {
| ^^^^^^ not found in `futures_util`
|
::: /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/docker-api-0.5.1/src/api/container/mod.rs:26:5
|
26 | / impl_api_ep! {container: Container, resp
27 | | Inspect -> &format!("/containers/{}/json", container.id)
28 | | Logs -> &format!("/containers/{}/logs", container.id)
29 | | DeleteWithOpts -> &format!("/containers/{}", container.id), String, delete
30 | | }
| |_____- in this macro invocation
|
= note: this error originates in the macro `impl_api_ep` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing one of these items
|
5 | use futures_util::stream::Stream;
|
5 | use std::stream::Stream;
|
5 | use core::stream::Stream;
|
Some errors have detailed explanations: E0405, E0432.
For more information about an error, try `rustc --explain E0405`.
error: could not compile `docker-api` due to 3 previous errors
Another thing is that docker-api = { version = "0.6.0" }
did not work. Apparently, version 0.5.1 is the latest I could get with cargo build.
docker version
on the command line:Server:
Engine:
Version: 20.10.7
API version: 1.41 (minimum version 1.12)
Go version: go1.13.8
Git commit: 20.10.7-0ubuntu5.1
Built: Thu Oct 21 23:58:58 2021
OS/Arch: linux/amd64
Experimental: true
containerd:
Version: 1.5.5-0ubuntu3
GitCommit:
runc:
Version: 1.0.1-0ubuntu2
GitCommit:
docker-init:
Version: 0.19.0
GitCommit:
Thank you so much for making this! It is just what I need.
It would be nice if the container state were an enum not a string.
docker version
on the command line:
the struct ContainerInfo
's layout seems not match to the docker api
Make sure both tty/no-tty cases are handle (#43).
Is it possible to add support for connecting to Docker using npipe:////./pipe/docker_engine
like in this guide? Currently I'm using tcp://localhost:2375
protocol. However, to use that protocol it is necessary to enable "Expose daemon on tcp://localhost:2375 without TLS" feature in Docker settings which is not convenient if you need to configure many machines. It is also slower and less secure.
Minor linting issues during build process
Hi,
I need to abstract logs
, but run into some lifetime / borrow issues. Is this just something generally not possible in this specific api due to rust or am i doing something wrong ?
use docker_api::opts::LogsOpts;
use docker_api::*;
use futures::{Stream, TryStreamExt,StreamExt};
use std::result::Result;
struct SomeWrapper {
runtime: Docker,
}
impl SomeWrapper {
fn logs(
&self,
container_id: &str,
) -> impl Stream<Item = Result<String, String>> + Send + Unpin {
let logs_opts = LogsOpts::builder()
//.follow(true)
.stdout(true)
.stderr(true)
.timestamps(true)
.build();
let container = self.runtime.containers().get(container_id);
let log_lines = container
.logs(&logs_opts)
.map_ok(|message| message.escape_ascii().to_string())
.map_err(|e| e.to_string());
log_lines
}
}
#[tokio::main]
async fn main() {
let w = SomeWrapper { runtime: Docker::new("/var/run/docker.socks").unwrap() };
let mut log_stream= w.logs("<someID>");
match log_stream.next().await {
Some(event) => {
dbg!(event);
}
None => {
println!("Channel Closed")
}
}
}
which leads to
error[E0597]: `container` does not live long enough
--> src\main.rs:23:25
|
22 | let container = self.runtime.containers().get(container_id);
| --------- binding `container` declared here
23 | let log_lines = container
| -^^^^^^^^
| |
| _________________________borrowed value does not live long enough
| |
24 | | .logs(&logs_opts)
| |_____________________________- argument requires that `container` is borrowed for `'static`
...
28 | }
| - `container` dropped here while still borrowed
For more information about this error, try `rustc --explain E0597`.
I tried lifetime annotations, Box , Rc but honestly i am totally lost and don't see how to solve this. With 'static
its still a error[E0515]: cannot return value referencing local variable
container`
error[E0515]: cannot return value referencing local variable `container`
--> src\main.rs:27:9
|
23 | let log_lines = container
| --------- `container` is borrowed here
...
27 | log_lines
| ^^^^^^^^^ returns a value referencing data owned by the current function
For more information about this error, try `rustc --explain E0515`.
error: could not compile `docker-logs` (bin "docker-logs") due to previous error
For events
that apporach is working fine, but i don't get it working for logs
.
self
.runtime
.events(&opts)
.map_ok(|message| message.escape_ascii().to_string())
.map_err(|e| e.to_string());
As far as I can tell there is currently no way to resize a container's TTY using this library. It seems to be possible to resize the TTY of an Exec Instance but not the native/entry-point TTY of a container. Api Reference For Container TTY Resize
Thank you!
Looks like there hasn't been any activity here in 9mos or so..
@vv9k is the plan for this to be actively maintained moving forward or is it better to stick to a fork?
Fix issue with error about implementation not being derived.
Checking docker-api v0.12.2 (/Users/casibbald/Workspace/microscaler/docker-api-rs)
error: this `impl` can be derived
--> src/opts/container.rs:51:1
|
51 | / impl Default for Isolation {
52 | | fn default() -> Self {
53 | | Isolation::Default
54 | | }
55 | | }
| |_^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#derivable_impls
= note: `-D clippy::derivable-impls` implied by `-D clippy::all`
= help: remove the manual implementation...
help: ...and instead derive it...
|
43 | #[derive(Default)]
|
help: ...and mark the default variant
|
45 ~ #[default]
46 ~ Default,
|
error: could not compile `docker-api` due to previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `docker-api` due to previous error
docker version
on the command line:Client: Docker Engine - Community
Version: 20.10.21
API version: 1.41
Go version: go1.18.7
Git commit: baeda1f
Built: Tue Oct 25 18:02:28 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.21
API version: 1.41 (minimum version 1.12)
Go version: go1.18.7
Git commit: 3056208
Built: Tue Oct 25 18:00:19 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.9
GitCommit: 1c90a442489720eec95342e1789ee8a5e1b9536f
runc:
Version: 1.1.4
GitCommit: v1.1.4-0-g5fd4c4d
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Hello, I tried to build a docker image with the example : cargo run --example image -- build .
This succeeds but it takes a very long time (~50 minutes), even with a simple Dockerfile. After some investigation, it seems that this is the sending of build context to the daemon that slows down the build.
For my test, I had the Dockerfile at the root of this repo, so it had to send ~1.8Gb of build context.
Doing the same test with the Dockerfile in an empty directory, the build is almost immediate.
Do you have any hint to reduce the build time when the build context is big ?
docker version
on the command line:Client:
Version: 20.10.18
API version: 1.41
Go version: go1.19.1
Git commit: b40c2f6b5d
Built: Sat Sep 10 11:31:10 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server:
Engine:
Version: 20.10.18
API version: 1.41 (minimum version 1.12)
Go version: go1.19.1
Git commit: e42327a6d3
Built: Sat Sep 10 11:30:17 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.6.8
GitCommit: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6.m
runc:
Version: 1.1.4
GitCommit:
docker-init:
Version: 0.19.0
GitCommit: de40ad0
When running the image example in the repo I get the following:
rukai@memes examples$ cargo run --example image -- list
Compiling docker-api v0.11.0 (/home/rukai2/Projects/Crates/docker-api-rs)
Finished dev [unoptimized + debuginfo] target(s) in 0.79s
Running `/home/rukai2/Projects/Crates/docker-api-rs/target/debug/examples/image list`
Error: invalid value: integer `-1`, expected usize at line 1 column 17
Examples like: cargo run --example container -- list
succeed for me.
TaskStatusInlineItem
doesn't have PortStatus
field, docker swagger doesn't have it too.
Status:
type: "object"
properties:
Timestamp:
type: "string"
format: "dateTime"
State:
$ref: "#/definitions/TaskState"
Message:
type: "string"
Err:
type: "string"
ContainerStatus:
type: "object"
properties:
ContainerID:
type: "string"
PID:
type: "integer"
ExitCode:
type: "integer"
But it present in source code
https://github.com/moby/moby/blob/master/api/types/swarm/task.go#L197
and may be acquired from
curl --silent -XGET --unix-socket /var/run/docker.sock http://localhost/tasks | jq .
{
"ID": "jz0dy04hqqiee7req68cn35sr",
"Version": {
"Index": 13330
},
"CreatedAt": "2023-07-21T17:11:15.900415099Z",
"UpdatedAt": "2023-07-21T17:11:18.903307684Z",
"Labels": {},
"Spec": {
"ContainerSpec": {
"Image": "nginx",
"Isolation": "default"
},
"ForceUpdate": 0
},
"ServiceID": "19q4qqid37yiht0ex82j89s4u",
"Slot": 2,
"NodeID": "d9y196uwpsfu83dub7wj9he9i",
"Status": {
"Timestamp": "2023-07-21T17:11:18.820798223Z",
"State": "running",
"Message": "started",
"ContainerStatus": {
"ContainerID": "6b319540150cd1c551db0ec80962435077910965ea4a96535444a40bf83dafb0",
"PID": 159542,
"ExitCode": 0
},
"PortStatus": {
"Ports": [
{
"Protocol": "tcp",
"TargetPort": 80,
"PublishedPort": 32774,
"PublishMode": "host"
},
{
"Protocol": "tcp",
"TargetPort": 80,
"PublishedPort": 32774,
"PublishMode": "host"
}
]
}
},
"DesiredState": "running",
"Volumes": null
}
docker version
on the command line: Version: 24.0.2
API version: 1.43
Go version: go1.20.4
Git commit: cb74dfcd85
Built: Mon May 29 15:50:06 2023
OS/Arch: linux/amd64
Context: default
Server:
Engine:
Version: 24.0.2
API version: 1.43 (minimum version 1.12)
Go version: go1.20.4
Git commit: 659604f9ee
Built: Mon May 29 15:50:06 2023
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.7.2
GitCommit: 0cae528dd6cb557f7201036e9f43420650207b58.m
runc:
Version: 1.1.8
GitCommit:
docker-init:
Version: 0.19.0
GitCommit: de40ad0
I am trying to implement the list docker images example in my own project, but something is wrong. I am missing something fundamental and would appreciate a review of this code:
async fn ListDockerImages() -> Result<(), Box<dyn std::error::Error>> {
let docker = Docker::unix("/var/run/docker.sock");
use docker_api::opts::ImageListOpts;
let opts = ImageListOpts::builder().all(true).build();
match docker.images().list(&opts).await {
Ok(images) => {
images.into_iter().for_each(|image| {
println!(
"---------------------------------\nCreated: {}\nId: {}\nRepo tags: {}\nLabels:\n{}",
image.created,
image.id,
image.repo_tags.join(","),
image
.labels
.into_iter()
.map(|(k, v)| format!(" - {}={}", k, v))
.collect::<Vec<_>>()
.join("\n"),
);
});
}
Err(e) => eprintln!("Problem listing docker images: {}", e),
}
Ok(())
}
#[tokio::main]
async fn main() {
ListDockerImages().await;
}
When I run this program, I get Problem listing docker images: invalid value: integer `-1`, expected usize at line 1 column 17
, not the actual listing I get when running the cargo run --example image -- list
.
What am I doing wrong that the example code is doing correctly? Thanks in advance.
Hi there!
We would love to be able to consume the latest crate release, however as the work to bump the models to 1.43 is on main we're using a temporary version off the primary branch in Git. If a patch release is possible, we'd be stoked.
Thank you for your work on this project--it has helped us out a lot! 🎉
It seems that there is no way to do docker commit
.
Putting in my vote for build args as it's a TODO
in the code 😃
docker-api-rs/src/opts/image.rs
Line 317 in b1f1891
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.