bollard_next/lib.rs
1//! [](https://crates.io/crates/bollard)
2//! [](https://opensource.org/licenses/Apache-2.0)
3//! [](https://circleci.com/gh/fussybeaver/bollard/tree/master)
4//! [](https://ci.appveyor.com/project/fussybeaver/boondock)
5//! [](https://docs.rs/bollard/)
6//!
7//! # Bollard: an asynchronous rust client library for the docker API
8//!
9//! Bollard leverages the latest [Hyper](https://github.com/hyperium/hyper) and
10//! [Tokio](https://github.com/tokio-rs/tokio) improvements for an asynchronous API containing
11//! futures, streams and the async/await paradigm.
12//!
13//! This library features Windows support through [Named
14//! Pipes](https://learn.microsoft.com/en-us/windows/win32/ipc/named-pipes) and HTTPS support through optional
15//! [Rustls](https://github.com/rustls/rustls) bindings. Serialization types for interfacing with
16//! [Docker](https://github.com/moby/moby) and [Buildkit](https://github.com/moby/buildkit) are
17//! generated through OpenAPI, protobuf and upstream documentation.
18//!
19//!
20//!
21//! # Install
22//!
23//! Add the following to your `Cargo.toml` file
24//!
25//! ```nocompile
26//! [dependencies]
27//! bollard = "*"
28//! ```
29//!
30//! # API
31//! ## Documentation
32//!
33//! [API docs](https://docs.rs/bollard/).
34//!
35//! ### Latest
36//!
37//! Version `0.17` enables the [`secrets`](https://docs.docker.com/build/building/secrets/#secret-mounts) and [`sshforward`](https://docs.docker.com/build/building/secrets/#ssh-mounts) components of
38//! `buildkit`, [API version 1.45.0](https://docs.docker.com/engine/api/v1.45/) - (disabled for
39//! windows).
40//! Please note: all `buildkit` API's are under *developer preview*, feedback is
41//! encouraged.
42//!
43//! ## Feature flags
44//!
45//! - `ssl`: enable SSL support through [Rustls](https://github.com/rustls/rustls) with the [ring](https://github.com/briansmith/ring) provider.
46//! - `aws-lc-rs`: enable SSL support through [Rustls](https://github.com/rustls/rustls) with the [aws-lc-rs](https://github.com/aws/aws-lc-rs) provider.
47//! - `ssl_providerless`: enable SSL support through [Rustls](https://github.com/rustls/rustls) without installing a [CryptoProvider](https://docs.rs/rustls/0.23.12/rustls/crypto/struct.CryptoProvider.html). You are responsible to do so.
48//! - `chrono`: enable [Chrono](https://github.com/chronotope/chrono) for `DateTime` types.
49//! - `time`: enable [Time 0.3](https://github.com/time-rs/time) for `DateTime` types.
50//! - `buildkit`: use [Buildkit](https://github.com/moby/buildkit) instead of
51//! [Docker](https://github.com/moby/moby) when building images.
52//! - `json_data_content`: Add JSON to errors on serialization failures.
53//! - `webpki`: Use mozilla's root certificates instead of native root certs provided by the OS.
54//!
55//! ## Version
56//!
57//! The [Docker API](https://docs.docker.com/engine/api/v1.44/) used by Bollard is using the latest
58//! `1.44` documentation schema published by the [moby](https://github.com/moby/moby) project to
59//! generate its serialization interface.
60//!
61//! Breaking change releases in Bollard will depend on a moby API server version corresponding to the
62//! date of that release, so for example a January minor version change will use the
63//! matching [moby swagger API](https://github.com/moby/moby/blob/master/api/swagger.yaml)
64//! available in January. The associated [`bollard-stubs`](https://crates.io/crate/bollard-stubs)
65//! project will release separate versions that you can pin your project against, if you need a
66//! more modern or older API according to your docker server version.
67//!
68//! For example:
69//! ```nocompile
70//! [dependencies]
71//! bollard-stubs = { version = "=1.44.0-rc.26.0.0" }
72//! ```
73//!
74//! This library also supports [version
75//! negotiation](https://docs.rs/bollard/latest/bollard/struct.Docker.html#method.negotiate_version),
76//! to allow downgrading to an older API version.
77//!
78//! # Usage
79//!
80//! ## Connecting with the docker daemon
81//!
82//! Connect to the docker server according to your architecture and security remit.
83//!
84//! ### Socket
85//!
86//! The client will connect to the standard unix socket location `/var/run/docker.sock` or Windows
87//! named pipe location `//./pipe/docker_engine`.
88//!
89//! ```rust
90//! use bollard_next::Docker;
91//! #[cfg(unix)]
92//! Docker::connect_with_socket_defaults();
93//! ```
94//!
95//! Use the `Docker::connect_with_socket` method API to parameterise this interface.
96//!
97//! ### Local
98//!
99//! The client will connect to the OS specific handler it is compiled for.
100//!
101//! This is a convenience for localhost environment that should run on multiple
102//! operating systems.
103//!
104//! ```rust
105//! use bollard_next::Docker;
106//! Docker::connect_with_local_defaults();
107//! ```
108//!
109//! Use the `Docker::connect_with_local` method API to parameterise this interface.
110//!
111//! ### HTTP
112//!
113//! The client will connect to the location pointed to by `DOCKER_HOST` environment variable, or
114//! `localhost:2375` if missing.
115//!
116//! ```rust
117//! use bollard_next::Docker;
118//! Docker::connect_with_http_defaults();
119//! ```
120//!
121//! Use the `Docker::connect_with_http` method API to parameterise the interface.
122//!
123//! ### SSL via Rustls
124//!
125//! The client will connect to the location pointed to by `DOCKER_HOST` environment variable, or
126//! `localhost:2375` if missing.
127//!
128//! The location pointed to by the `DOCKER_CERT_PATH` environment variable is searched for
129//! certificates - `key.pem` for the private key, `cert.pem` for the server certificate and
130//! `ca.pem` for the certificate authority chain.
131//!
132//! ```rust
133//! use bollard_next::Docker;
134//! #[cfg(feature = "ssl")]
135//! Docker::connect_with_ssl_defaults();
136//! ```
137//!
138//! Use the `Docker::connect_with_ssl` method API to parameterise the interface.
139//!
140//! ## Examples
141//!
142//! Note: all these examples need a [Tokio
143//! Runtime](https://tokio.rs/).
144//!
145//! ### Version
146//!
147//! First, check that the API is working with your server:
148//!
149//! ```rust,no_run
150//! use bollard_next::Docker;
151//!
152//! use futures_util::future::FutureExt;
153//!
154//! // Use a connection function described above
155//! // let docker = Docker::connect_...;
156//! # let docker = Docker::connect_with_local_defaults().unwrap();
157//!
158//! async move {
159//! let version = docker.version().await.unwrap();
160//! println!("{:?}", version);
161//! };
162//! ```
163//!
164//! ### Listing images
165//!
166//! To list docker images available on the Docker server:
167//!
168//! ```rust,no_run
169//! use bollard_next::Docker;
170//! use bollard_next::image::ListImagesOptions;
171//!
172//! use futures_util::future::FutureExt;
173//!
174//! use std::default::Default;
175//!
176//! // Use a connection function described above
177//! // let docker = Docker::connect_...;
178//! # let docker = Docker::connect_with_local_defaults().unwrap();
179//!
180//! async move {
181//! let images = &docker.list_images(Some(ListImagesOptions::<String> {
182//! all: true,
183//! ..Default::default()
184//! })).await.unwrap();
185//!
186//! for image in images {
187//! println!("-> {:?}", image);
188//! }
189//! };
190//! ```
191//!
192//! ## Streaming Stats
193//!
194//! To receive a stream of stats for a running container.
195//!
196//! ```rust,no_run
197//! use bollard_next::Docker;
198//! use bollard_next::container::StatsOptions;
199//!
200//! use futures_util::stream::TryStreamExt;
201//!
202//! use std::default::Default;
203//!
204//! // Use a connection function described above
205//! // let docker = Docker::connect_...;
206//! # let docker = Docker::connect_with_local_defaults().unwrap();
207//!
208//! async move {
209//! let stats = &docker.stats("postgres", Some(StatsOptions {
210//! stream: true,
211//! ..Default::default()
212//! })).try_collect::<Vec<_>>().await.unwrap();
213//!
214//! for stat in stats {
215//! println!("{} - mem total: {:?} | mem usage: {:?}",
216//! stat.name,
217//! stat.memory_stats.max_usage,
218//! stat.memory_stats.usage);
219//! }
220//! };
221//! ```
222//!
223//! # Examples
224//!
225//! Further examples are available in the [examples
226//! folder](https://github.com/fussybeaver/bollard/tree/master/examples), or the [integration/unit
227//! tests](https://github.com/fussybeaver/bollard/tree/master/tests).
228//!
229//! # Development
230//!
231//! Contributions are welcome, please observe the following.
232//!
233//! ## Building the proto models
234//!
235//! Serialization models for the buildkit feature are generated through the [Tonic
236//! library](https://github.com/hyperium/tonic/). To generate these files, use the
237//! following in the `codegen/proto` folder:
238//!
239//! ```bash
240//! cargo run --bin gen --features build
241//! ```
242//!
243//! ## Building the swagger models
244//!
245//! Serialization models are generated through the [Swagger
246//! library](https://github.com/swagger-api/swagger-codegen/). To generate these files, use the
247//! following in the `codegen/swagger` folder:
248//!
249//! ```bash
250//! mvn -D org.slf4j.simpleLogger.defaultLogLevel=error compiler:compile generate-resources
251//! ```
252//!
253//! # Integration tests
254//!
255//! Running the integration tests by default requires a running docker registry, with images tagged
256//! and pushed there. To disable this behaviour, set the `DISABLE_REGISTRY` environment variable.
257//!
258//! ```bash
259//! docker run -d --restart always --name registry -p 5000:5000 registry:2
260//! docker pull hello-world:linux
261//! docker pull fussybeaver/uhttpd
262//! docker pull alpine
263//! docker tag hello-world:linux localhost:5000/hello-world:linux
264//! docker tag fussybeaver/uhttpd localhost:5000/fussybeaver/uhttpd
265//! docker tag alpine localhost:5000/alpine
266//! docker push localhost:5000/hello-world:linux
267//! docker push localhost:5000/fussybeaver/uhttpd
268//! docker push localhost:5000/alpine
269//! docker swarm init
270//! REGISTRY_HTTP_ADDR=localhost:5000 cargo test -- --test-threads 1
271//! ```
272#![deny(
273 missing_docs,
274 missing_debug_implementations,
275 missing_copy_implementations,
276 trivial_casts,
277 trivial_numeric_casts,
278 //unstable_features,
279 unused_import_braces,
280)]
281#![allow(
282 clippy::upper_case_acronyms,
283 clippy::derive_partial_eq_without_eq,
284 async_fn_in_trait
285)]
286#![warn(rust_2018_idioms)]
287
288// declare modules
289pub mod auth;
290pub mod container;
291mod docker;
292pub mod errors;
293pub mod exec;
294pub mod image;
295pub mod network;
296mod read;
297pub mod secret;
298pub mod service;
299pub mod system;
300mod uri;
301pub mod volume;
302
303pub mod grpc;
304
305// publicly re-export
306pub use crate::docker::{BollardRequest, ClientVersion, Docker, API_DEFAULT_VERSION};
307pub use bollard_next_stubs::models;
308
309#[cfg(feature = "buildkit")]
310pub use bollard_buildkit_proto::fsutil;
311
312#[cfg(feature = "buildkit")]
313pub use bollard_buildkit_proto::health;
314
315#[cfg(feature = "buildkit")]
316pub use bollard_buildkit_proto::moby;