pangu_bollard/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.14` enables a `buildkit` feature for builds using public images (check the
38//! [buildkit example](https://github.com/fussybeaver/bollard/blob/v0.14.0/examples/build_buildkit.rs)
39//! for details on how to configure).
40//!
41//! ## Feature flags
42//!
43//! - `ssl`: enable SSL support through [Rustls](https://github.com/rustls/rustls)
44//! - `chrono`: enable [Chrono](https://github.com/chronotope/chrono) for `DateTime` types.
45//! - `time`: enable [Time 0.3](https://github.com/time-rs/time) for `DateTime` types.
46//! - `buildkit`: use [Buildkit](https://github.com/moby/buildkit) instead of
47//! [Docker](https://github.com/moby/moby) when building images.
48//! - `json_data_content`: Add JSON to errors on serialization failures.
49//! - `ct_logs`: [Certificate transparency](https://certificate.transparency.dev/howctworks/)
50//! verification (requires `ssl`).
51//!
52//! ## Version
53//!
54//! The [Docker API](https://docs.docker.com/engine/api/v1.41/) used by Bollard is using the latest
55//! `1.41` documentation schema published by the [moby](https://github.com/moby/moby) project to
56//! generate its serialization interface.
57//!
58//! This library also supports [version
59//! negotiation](https://docs.rs/bollard/latest/bollard/struct.Docker.html#method.negotiate_version),
60//! to allow downgrading to an older API version.
61//!
62//! # Usage
63//!
64//! ## Connecting with the docker daemon
65//!
66//! Connect to the docker server according to your architecture and security remit.
67//!
68//! ### Socket
69//!
70//! The client will connect to the standard unix socket location `/var/run/docker.sock` or Windows
71//! named pipe location `//./pipe/docker_engine`.
72//!
73//! ```rust
74//! use bollard::Docker;
75//! #[cfg(unix)]
76//! Docker::connect_with_socket_defaults();
77//! ```
78//!
79//! Use the `Docker::connect_with_socket` method API to parameterise this interface.
80//!
81//! ### Local
82//!
83//! The client will connect to the OS specific handler it is compiled for.
84//!
85//! This is a convenience for localhost environment that should run on multiple
86//! operating systems.
87//!
88//! ```rust
89//! use bollard::Docker;
90//! Docker::connect_with_local_defaults();
91//! ```
92//!
93//! Use the `Docker::connect_with_local` method API to parameterise this interface.
94//!
95//! ### HTTP
96//!
97//! The client will connect to the location pointed to by `DOCKER_HOST` environment variable, or
98//! `localhost:2375` if missing.
99//!
100//! ```rust
101//! use bollard::Docker;
102//! Docker::connect_with_http_defaults();
103//! ```
104//!
105//! Use the `Docker::connect_with_http` method API to parameterise the interface.
106//!
107//! ### SSL via Rustls
108//!
109//! The client will connect to the location pointed to by `DOCKER_HOST` environment variable, or
110//! `localhost:2375` if missing.
111//!
112//! The location pointed to by the `DOCKER_CERT_PATH` environment variable is searched for
113//! certificates - `key.pem` for the private key, `cert.pem` for the server certificate and
114//! `ca.pem` for the certificate authority chain.
115//!
116//! ```rust
117//! use bollard::Docker;
118//! #[cfg(feature = "ssl")]
119//! Docker::connect_with_ssl_defaults();
120//! ```
121//!
122//! Use the `Docker::connect_with_ssl` method API to parameterise the interface.
123//!
124//! ## Examples
125//!
126//! Note: all these examples need a [Tokio
127//! Runtime](https://tokio.rs/).
128//!
129//! ### Version
130//!
131//! First, check that the API is working with your server:
132//!
133//! ```rust,no_run
134//! use bollard::Docker;
135//!
136//! use futures_util::future::FutureExt;
137//!
138//! // Use a connection function described above
139//! // let docker = Docker::connect_...;
140//! # let docker = Docker::connect_with_local_defaults().unwrap();
141//!
142//! async move {
143//! let version = docker.version().await.unwrap();
144//! println!("{:?}", version);
145//! };
146//! ```
147//!
148//! ### Listing images
149//!
150//! To list docker images available on the Docker server:
151//!
152//! ```rust,no_run
153//! use bollard::Docker;
154//! use bollard::image::ListImagesOptions;
155//!
156//! use futures_util::future::FutureExt;
157//!
158//! use std::default::Default;
159//!
160//! // Use a connection function described above
161//! // let docker = Docker::connect_...;
162//! # let docker = Docker::connect_with_local_defaults().unwrap();
163//!
164//! async move {
165//! let images = &docker.list_images(Some(ListImagesOptions::<String> {
166//! all: true,
167//! ..Default::default()
168//! })).await.unwrap();
169//!
170//! for image in images {
171//! println!("-> {:?}", image);
172//! }
173//! };
174//! ```
175//!
176//! ## Streaming Stats
177//!
178//! To receive a stream of stats for a running container.
179//!
180//! ```rust,no_run
181//! use bollard::Docker;
182//! use bollard::container::StatsOptions;
183//!
184//! use futures_util::stream::TryStreamExt;
185//!
186//! use std::default::Default;
187//!
188//! // Use a connection function described above
189//! // let docker = Docker::connect_...;
190//! # let docker = Docker::connect_with_local_defaults().unwrap();
191//!
192//! async move {
193//! let stats = &docker.stats("postgres", Some(StatsOptions {
194//! stream: true,
195//! ..Default::default()
196//! })).try_collect::<Vec<_>>().await.unwrap();
197//!
198//! for stat in stats {
199//! println!("{} - mem total: {:?} | mem usage: {:?}",
200//! stat.name,
201//! stat.memory_stats.max_usage,
202//! stat.memory_stats.usage);
203//! }
204//! };
205//! ```
206//!
207//! # Examples
208//!
209//! Further examples are available in the [examples
210//! folder](https://github.com/fussybeaver/bollard/tree/master/examples), or the [integration/unit
211//! tests](https://github.com/fussybeaver/bollard/tree/master/tests).
212//!
213//! # Development
214//!
215//! Contributions are welcome, please observe the following.
216//!
217//! ## Building the proto models
218//!
219//! Serialization models for the buildkit feature are generated through the [Tonic
220//! library](https://github.com/hyperium/tonic/). To generate these files, use the
221//! following in the `codegen/proto` folder:
222//!
223//! ```bash
224//! cargo run --bin gen --features build
225//! ```
226//!
227//! ## Building the swagger models
228//!
229//! Serialization models are generated through the [Swagger
230//! library](https://github.com/swagger-api/swagger-codegen/). To generate these files, use the
231//! following in the `codegen/swagger` folder:
232//!
233//! ```bash
234//! mvn -D org.slf4j.simpleLogger.defaultLogLevel=error compiler:compile generate-resources
235//! ```
236//!
237//! # Integration tests
238//!
239//! Running the integration tests by default requires a running docker registry, with images tagged
240//! and pushed there. To disable this behaviour, set the `DISABLE_REGISTRY` environment variable.
241//!
242//! ```bash
243//! docker run -d --restart always --name registry -p 5000:5000 registry:2
244//! docker pull hello-world:linux
245//! docker pull fussybeaver/uhttpd
246//! docker pull alpine
247//! docker tag hello-world:linux localhost:5000/hello-world:linux
248//! docker tag fussybeaver/uhttpd localhost:5000/fussybeaver/uhttpd
249//! docker tag alpine localhost:5000/alpine
250//! docker push localhost:5000/hello-world:linux
251//! docker push localhost:5000/fussybeaver/uhttpd
252//! docker push localhost:5000/alpine
253//! docker swarm init
254//! REGISTRY_HTTP_ADDR=localhost:5000 cargo test -- --test-threads 1
255//! ```
256#![deny(
257 missing_docs,
258 missing_debug_implementations,
259 missing_copy_implementations,
260 trivial_casts,
261 trivial_numeric_casts,
262 unstable_features,
263 unused_import_braces,
264 unused_qualifications
265)]
266#![allow(clippy::upper_case_acronyms, clippy::derive_partial_eq_without_eq)]
267#![warn(rust_2018_idioms)]
268
269#[macro_use]
270extern crate serde_derive;
271#[macro_use]
272extern crate log;
273
274// declare modules
275pub mod auth;
276pub mod container;
277mod docker;
278pub mod errors;
279pub mod exec;
280pub mod image;
281mod named_pipe;
282pub mod network;
283mod read;
284pub mod secret;
285pub mod service;
286pub mod system;
287mod uri;
288pub mod volume;
289
290pub mod grpc;
291
292// publicly re-export
293pub use crate::docker::{ClientVersion, Docker, API_DEFAULT_VERSION};
294pub use bollard_stubs::models;
295
296#[cfg(feature = "buildkit")]
297pub use bollard_buildkit_proto::health;
298
299#[cfg(feature = "buildkit")]
300pub use bollard_buildkit_proto::moby;