-
Notifications
You must be signed in to change notification settings - Fork 137
/
container.rs
2266 lines (2086 loc) · 66.5 KB
/
container.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//! Container API: run docker containers and manage their lifecycle
use futures_core::Stream;
use futures_util::{StreamExt, TryStreamExt};
use http::header::{CONNECTION, CONTENT_TYPE, UPGRADE};
use http::request::Builder;
use hyper::{body::Bytes, Body, Method};
use serde::Serialize;
use tokio::io::AsyncWrite;
use tokio_util::codec::FramedRead;
use std::cmp::Eq;
use std::collections::HashMap;
use std::fmt;
use std::hash::Hash;
use std::pin::Pin;
use super::Docker;
use crate::errors::Error;
use crate::models::*;
use crate::read::NewlineLogOutputDecoder;
/// Parameters used in the [List Container API](Docker::list_containers())
///
/// ## Examples
///
/// ```rust
/// use bollard::container::ListContainersOptions;
///
/// use std::collections::HashMap;
/// use std::default::Default;
///
/// let mut filters = HashMap::new();
/// filters.insert("health", vec!["unhealthy"]);
///
/// ListContainersOptions{
/// all: true,
/// filters,
/// ..Default::default()
/// };
/// ```
///
/// ```rust
/// # use bollard::container::ListContainersOptions;
/// # use std::default::Default;
/// ListContainersOptions::<String>{
/// ..Default::default()
/// };
/// ```
#[derive(Debug, Clone, Default, PartialEq, Serialize)]
pub struct ListContainersOptions<T>
where
T: Into<String> + Eq + Hash + Serialize,
{
/// Return all containers. By default, only running containers are shown
pub all: bool,
/// Return this number of most recently created containers, including non-running ones
pub limit: Option<isize>,
/// Return the size of container as fields `SizeRw` and `SizeRootFs`
pub size: bool,
/// Filters to process on the container list, encoded as JSON. Available filters:
/// - `ancestor`=`(<image-name>[:<tag>]`, `<image id>`, or `<image@digest>`)
/// - `before`=(`<container id>` or `<container name>`)
/// - `expose`=(`<port>[/<proto>]`|`<startport-endport>`/`[<proto>]`)
/// - `exited`=`<int>` containers with exit code of `<int>`
/// - `health`=(`starting`|`healthy`|`unhealthy`|`none`)
/// - `id`=`<ID>` a container's ID
/// - `isolation`=(`default`|`process`|`hyperv`) (Windows daemon only)
/// - `is-task`=`(true`|`false`)
/// - `label`=`key` or `label`=`"key=value"` of a container label
/// - `name`=`<name>` a container's name
/// - `network`=(`<network id>` or `<network name>`)
/// - `publish`=(`<port>[/<proto>]`|`<startport-endport>`/`[<proto>]`)
/// - `since`=(`<container id>` or `<container name>`)
/// - `status`=(`created`|`restarting`|`running`|`removing`|`paused`|`exited`|`dead`)
/// - `volume`=(`<volume name>` or `<mount point destination>`)
#[serde(serialize_with = "crate::docker::serialize_as_json")]
pub filters: HashMap<T, Vec<T>>,
}
/// Parameters used in the [Create Container API](Docker::create_container())
///
/// ## Examples
///
/// ```rust
/// use bollard::container::CreateContainerOptions;
///
/// CreateContainerOptions{
/// name: "my-new-container",
/// platform: Some("linux/amd64"),
/// };
/// ```
#[derive(Debug, Clone, Default, PartialEq, Serialize)]
pub struct CreateContainerOptions<T>
where
T: Into<String> + Serialize,
{
/// Assign the specified name to the container.
pub name: T,
/// The platform to use for the container.
/// Added in API v1.41.
#[serde(skip_serializing_if = "Option::is_none")]
pub platform: Option<T>,
}
/// This container's networking configuration.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
#[allow(missing_docs)]
pub struct NetworkingConfig<T: Into<String> + Hash + Eq> {
pub endpoints_config: HashMap<T, EndpointSettings>,
}
/// Container to create.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct Config<T>
where
T: Into<String> + Eq + Hash,
{
/// The hostname to use for the container, as a valid RFC 1123 hostname.
#[serde(rename = "Hostname")]
#[serde(skip_serializing_if = "Option::is_none")]
pub hostname: Option<T>,
/// The domain name to use for the container.
#[serde(rename = "Domainname")]
#[serde(skip_serializing_if = "Option::is_none")]
pub domainname: Option<T>,
/// The user that commands are run as inside the container.
#[serde(rename = "User")]
#[serde(skip_serializing_if = "Option::is_none")]
pub user: Option<T>,
/// Whether to attach to `stdin`.
#[serde(rename = "AttachStdin")]
#[serde(skip_serializing_if = "Option::is_none")]
pub attach_stdin: Option<bool>,
/// Whether to attach to `stdout`.
#[serde(rename = "AttachStdout")]
#[serde(skip_serializing_if = "Option::is_none")]
pub attach_stdout: Option<bool>,
/// Whether to attach to `stderr`.
#[serde(rename = "AttachStderr")]
#[serde(skip_serializing_if = "Option::is_none")]
pub attach_stderr: Option<bool>,
/// An object mapping ports to an empty object in the form: `{\"<port>/<tcp|udp|sctp>\": {}}`
#[serde(rename = "ExposedPorts")]
#[serde(skip_serializing_if = "Option::is_none")]
pub exposed_ports: Option<HashMap<T, HashMap<(), ()>>>,
/// Attach standard streams to a TTY, including `stdin` if it is not closed.
#[serde(rename = "Tty")]
#[serde(skip_serializing_if = "Option::is_none")]
pub tty: Option<bool>,
/// Open `stdin`
#[serde(rename = "OpenStdin")]
#[serde(skip_serializing_if = "Option::is_none")]
pub open_stdin: Option<bool>,
/// Close `stdin` after one attached client disconnects
#[serde(rename = "StdinOnce")]
#[serde(skip_serializing_if = "Option::is_none")]
pub stdin_once: Option<bool>,
/// A list of environment variables to set inside the container in the form `[\"VAR=value\", ...]`. A variable without `=` is removed from the environment, rather than to have an empty value.
#[serde(rename = "Env")]
#[serde(skip_serializing_if = "Option::is_none")]
pub env: Option<Vec<T>>,
/// Command to run specified as a string or an array of strings.
#[serde(rename = "Cmd")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cmd: Option<Vec<T>>,
/// A TEST to perform TO Check that the container is healthy.
#[serde(rename = "Healthcheck")]
#[serde(skip_serializing_if = "Option::is_none")]
pub healthcheck: Option<HealthConfig>,
/// Command is already escaped (Windows only)
#[serde(rename = "ArgsEscaped")]
#[serde(skip_serializing_if = "Option::is_none")]
pub args_escaped: Option<bool>,
/// The name of the image to use when creating the container
#[serde(rename = "Image")]
#[serde(skip_serializing_if = "Option::is_none")]
pub image: Option<T>,
/// An object mapping mount point paths inside the container to empty objects.
#[serde(rename = "Volumes")]
#[serde(skip_serializing_if = "Option::is_none")]
pub volumes: Option<HashMap<T, HashMap<(), ()>>>,
/// The working directory for commands to run in.
#[serde(rename = "WorkingDir")]
#[serde(skip_serializing_if = "Option::is_none")]
pub working_dir: Option<T>,
/// The entry point for the container as a string or an array of strings. If the array consists of exactly one empty string (`[\"\"]`) then the entry point is reset to system default (i.e., the entry point used by docker when there is no `ENTRYPOINT` instruction in the `Dockerfile`).
#[serde(rename = "Entrypoint")]
#[serde(skip_serializing_if = "Option::is_none")]
pub entrypoint: Option<Vec<T>>,
/// Disable networking for the container.
#[serde(rename = "NetworkDisabled")]
#[serde(skip_serializing_if = "Option::is_none")]
pub network_disabled: Option<bool>,
/// MAC address of the container.
#[serde(rename = "MacAddress")]
#[serde(skip_serializing_if = "Option::is_none")]
pub mac_address: Option<T>,
/// `ONBUILD` metadata that were defined in the image's `Dockerfile`.
#[serde(rename = "OnBuild")]
#[serde(skip_serializing_if = "Option::is_none")]
pub on_build: Option<Vec<T>>,
/// User-defined key/value metadata.
#[serde(rename = "Labels")]
#[serde(skip_serializing_if = "Option::is_none")]
pub labels: Option<HashMap<T, T>>,
/// Signal to stop a container as a string or unsigned integer.
#[serde(rename = "StopSignal")]
#[serde(skip_serializing_if = "Option::is_none")]
pub stop_signal: Option<T>,
/// Timeout to stop a container in seconds.
#[serde(rename = "StopTimeout")]
#[serde(skip_serializing_if = "Option::is_none")]
pub stop_timeout: Option<i64>,
/// Shell for when `RUN`, `CMD`, and `ENTRYPOINT` uses a shell.
#[serde(rename = "Shell")]
#[serde(skip_serializing_if = "Option::is_none")]
pub shell: Option<Vec<T>>,
/// Container configuration that depends on the host we are running on.
/// Shell for when `RUN`, `CMD`, and `ENTRYPOINT` uses a shell.
#[serde(rename = "HostConfig")]
#[serde(skip_serializing_if = "Option::is_none")]
pub host_config: Option<HostConfig>,
/// This container's networking configuration.
#[serde(rename = "NetworkingConfig")]
#[serde(skip_serializing_if = "Option::is_none")]
pub networking_config: Option<NetworkingConfig<T>>,
}
impl From<ContainerConfig> for Config<String> {
fn from(container: ContainerConfig) -> Self {
Config {
hostname: container.hostname,
domainname: container.domainname,
user: container.user,
attach_stdin: container.attach_stdin,
attach_stdout: container.attach_stdout,
attach_stderr: container.attach_stderr,
exposed_ports: container.exposed_ports,
tty: container.tty,
open_stdin: container.open_stdin,
stdin_once: container.stdin_once,
env: container.env,
cmd: container.cmd,
healthcheck: container.healthcheck,
args_escaped: container.args_escaped,
image: container.image,
volumes: container.volumes,
working_dir: container.working_dir,
entrypoint: container.entrypoint,
network_disabled: container.network_disabled,
mac_address: container.mac_address,
on_build: container.on_build,
labels: container.labels,
stop_signal: container.stop_signal,
stop_timeout: container.stop_timeout,
shell: container.shell,
host_config: None,
networking_config: None,
}
}
}
/// Parameters used in the [Stop Container API](Docker::stop_container())
///
/// ## Examples
///
/// use bollard::container::StopContainerOptions;
///
/// StopContainerOptions{
/// t: 30,
/// };
#[derive(Debug, Copy, Clone, Default, PartialEq, Serialize)]
pub struct StopContainerOptions {
/// Number of seconds to wait before killing the container
pub t: i64,
}
/// Parameters used in the [Start Container API](Docker::start_container())
///
/// ## Examples
///
/// ```rust
/// use bollard::container::StartContainerOptions;
///
/// StartContainerOptions{
/// detach_keys: "ctrl-^"
/// };
/// ```
#[derive(Debug, Clone, Default, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct StartContainerOptions<T>
where
T: Into<String> + Serialize,
{
/// Override the key sequence for detaching a container. Format is a single character `[a-Z]` or
/// `ctrl-<value>` where `<value>` is one of: `a-z`, `@`, `^`, `[`, `,` or `_`.
pub detach_keys: T,
}
/// Parameters used in the [Remove Container API](Docker::remove_container())
///
/// ## Examples
///
/// ```rust
/// use bollard::container::RemoveContainerOptions;
///
/// use std::default::Default;
///
/// RemoveContainerOptions{
/// force: true,
/// ..Default::default()
/// };
/// ```
#[derive(Debug, Copy, Clone, Default, PartialEq, Serialize)]
pub struct RemoveContainerOptions {
/// Remove the volumes associated with the container.
pub v: bool,
/// If the container is running, kill it before removing it.
pub force: bool,
/// Remove the specified link associated with the container.
pub link: bool,
}
/// Parameters used in the [Wait Container API](Docker::wait_container())
///
/// ## Examples
///
/// ```rust
/// use bollard::container::WaitContainerOptions;
///
/// WaitContainerOptions{
/// condition: "not-running",
/// };
/// ```
#[derive(Debug, Clone, Default, PartialEq, Serialize)]
pub struct WaitContainerOptions<T>
where
T: Into<String> + Serialize,
{
/// Wait until a container state reaches the given condition, either 'not-running' (default),
/// 'next-exit', or 'removed'.
pub condition: T,
}
/// Results type for the [Attach Container API](Docker::attach_container())
pub struct AttachContainerResults {
/// [Log Output](LogOutput) enum, wrapped in a Stream.
pub output: Pin<Box<dyn Stream<Item = Result<LogOutput, Error>> + Send>>,
/// Byte writer to container
pub input: Pin<Box<dyn AsyncWrite + Send>>,
}
impl fmt::Debug for AttachContainerResults {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "AttachContainerResults")
}
}
/// Parameters used in the [Attach Container API](Docker::attach_container())
///
/// ## Examples
///
/// ```rust
/// use bollard::container::AttachContainerOptions;
///
/// AttachContainerOptions::<String>{
/// stdin: Some(true),
/// stdout: Some(true),
/// stderr: Some(true),
/// stream: Some(true),
/// logs: Some(true),
/// detach_keys: Some("ctrl-c".to_string()),
/// };
/// ```
#[derive(Debug, Copy, Clone, Default, PartialEq, Serialize)]
pub struct AttachContainerOptions<T>
where
T: Into<String> + Serialize + Default,
{
/// Attach to `stdin`
pub stdin: Option<bool>,
/// Attach to `stdout`
pub stdout: Option<bool>,
/// Attach to `stderr`
pub stderr: Option<bool>,
/// Stream attached streams from the time the request was made onwards.
pub stream: Option<bool>,
/// Replay previous logs from the container.
/// This is useful for attaching to a container that has started and you want to output everything since the container started.
/// If stream is also enabled, once all the previous output has been returned, it will seamlessly transition into streaming current output.
pub logs: Option<bool>,
/// Override the key sequence for detaching a container.
/// Format is a single character [a-Z] or ctrl-\<value\> where \<value\> is one of: a-z, @, ^, [, , or _.
#[serde(rename = "detachKeys")]
pub detach_keys: Option<T>,
}
/// Parameters used in the [Resize Container Tty API](Docker::resize_container_tty())
///
/// ## Examples
///
/// ```rust
/// use bollard::container::ResizeContainerTtyOptions;
///
/// ResizeContainerTtyOptions {
/// width: 50,
/// height: 10,
/// };
/// ```
#[derive(Debug, Copy, Clone, Default, PartialEq, Serialize)]
pub struct ResizeContainerTtyOptions {
/// Width of the TTY session in characters
#[serde(rename = "w")]
pub width: u16,
/// Height of the TTY session in characters
#[serde(rename = "h")]
pub height: u16,
}
/// Parameters used in the [Restart Container API](Docker::restart_container())
///
/// ## Example
///
/// ```rust
/// use bollard::container::RestartContainerOptions;
///
/// RestartContainerOptions{
/// t: 30,
/// };
/// ```
#[derive(Debug, Copy, Clone, Default, PartialEq, Serialize)]
pub struct RestartContainerOptions {
/// Number of seconds to wait before killing the container.
pub t: isize,
}
/// Parameters used in the [Inspect Container API](Docker::inspect_container())
///
/// ## Examples
///
/// ```rust
/// use bollard::container::InspectContainerOptions;
///
/// InspectContainerOptions{
/// size: false,
/// };
/// ```
#[derive(Debug, Copy, Clone, Default, PartialEq, Serialize)]
pub struct InspectContainerOptions {
/// Return the size of container as fields `SizeRw` and `SizeRootFs`
pub size: bool,
}
/// Parameters used in the [Top Processes API](Docker::top_processes())
///
/// ## Examples
///
/// ```rust
/// use bollard::container::TopOptions;
///
/// TopOptions{
/// ps_args: "aux",
/// };
/// ```
#[derive(Debug, Clone, Default, PartialEq, Serialize)]
pub struct TopOptions<T>
where
T: Into<String> + Serialize,
{
/// The arguments to pass to `ps`. For example, `aux`
pub ps_args: T,
}
fn is_zero(val: &i64) -> bool {
val == &0i64
}
/// Parameters used in the [Logs API](Docker::logs())
///
/// ## Examples
///
/// ```rust
/// use bollard::container::LogsOptions;
///
/// use std::default::Default;
///
/// LogsOptions::<String>{
/// stdout: true,
/// ..Default::default()
/// };
/// ```
#[derive(Debug, Clone, Default, PartialEq, Serialize)]
pub struct LogsOptions<T>
where
T: Into<String> + Serialize,
{
/// Return the logs as a finite stream.
pub follow: bool,
/// Return logs from `stdout`.
pub stdout: bool,
/// Return logs from `stderr`.
pub stderr: bool,
/// Only return logs since this time, as a UNIX timestamp.
pub since: i64,
/// Only return logs before this time, as a UNIX timestamp.
#[serde(skip_serializing_if = "is_zero")]
// workaround for https://github.com/containers/podman/issues/10859
pub until: i64,
/// Add timestamps to every log line.
pub timestamps: bool,
/// Only return this number of log lines from the end of the logs. Specify as an integer or all
/// to output `all` log lines.
pub tail: T,
}
/// Result type for the [Logs API](Docker::logs())
#[derive(Debug, Clone, PartialEq)]
#[allow(missing_docs)]
pub enum LogOutput {
StdErr { message: Bytes },
StdOut { message: Bytes },
StdIn { message: Bytes },
Console { message: Bytes },
}
impl fmt::Display for LogOutput {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let message = match &self {
LogOutput::StdErr { message } => message,
LogOutput::StdOut { message } => message,
LogOutput::StdIn { message } => message,
LogOutput::Console { message } => message,
};
write!(f, "{}", String::from_utf8_lossy(message))
}
}
impl AsRef<[u8]> for LogOutput {
fn as_ref(&self) -> &[u8] {
match self {
LogOutput::StdErr { message } => message.as_ref(),
LogOutput::StdOut { message } => message.as_ref(),
LogOutput::StdIn { message } => message.as_ref(),
LogOutput::Console { message } => message.as_ref(),
}
}
}
impl LogOutput {
/// Get the raw bytes of the output
pub fn into_bytes(self) -> Bytes {
match self {
LogOutput::StdErr { message } => message,
LogOutput::StdOut { message } => message,
LogOutput::StdIn { message } => message,
LogOutput::Console { message } => message,
}
}
}
/// Parameters used in the [Stats API](super::Docker::stats())
///
/// ## Examples
///
/// ```rust
/// use bollard::container::StatsOptions;
///
/// StatsOptions{
/// stream: false,
/// one_shot: false,
/// };
/// ```
#[derive(Debug, Copy, Clone, Default, PartialEq, Serialize)]
pub struct StatsOptions {
/// Stream the output. If false, the stats will be output once and then it will disconnect.
pub stream: bool,
/// Only get a single stat instead of waiting for 2 cycles. Must be used with `stream = false`.
#[serde(rename = "one-shot")]
pub one_shot: bool,
}
/// Granular memory statistics for the container.
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
#[allow(missing_docs)]
#[serde(untagged)]
pub enum MemoryStatsStats {
V1(MemoryStatsStatsV1),
V2(MemoryStatsStatsV2),
}
/// Granular memory statistics for the container, v1 cgroups.
///
/// Exposed in the docker library [here](https://github.com/moby/moby/blob/40d9e2aff130b42ba0f83d5238b9b53184c8ab3b/daemon/daemon_unix.go#L1436).
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
#[allow(missing_docs)]
#[serde(deny_unknown_fields)]
pub struct MemoryStatsStatsV1 {
pub cache: u64,
pub dirty: u64,
pub mapped_file: u64,
pub total_inactive_file: u64,
pub pgpgout: u64,
pub rss: u64,
pub total_mapped_file: u64,
pub writeback: u64,
pub unevictable: u64,
pub pgpgin: u64,
pub total_unevictable: u64,
pub pgmajfault: u64,
pub total_rss: u64,
pub total_rss_huge: u64,
pub total_writeback: u64,
pub total_inactive_anon: u64,
pub rss_huge: u64,
pub hierarchical_memory_limit: u64,
pub total_pgfault: u64,
pub total_active_file: u64,
pub active_anon: u64,
pub total_active_anon: u64,
pub total_pgpgout: u64,
pub total_cache: u64,
pub total_dirty: u64,
pub inactive_anon: u64,
pub active_file: u64,
pub pgfault: u64,
pub inactive_file: u64,
pub total_pgmajfault: u64,
pub total_pgpgin: u64,
pub hierarchical_memsw_limit: Option<u64>, // only on OSX
pub shmem: Option<u64>, // only on linux kernel > 4.15.0-1106
pub total_shmem: Option<u64>, // only on linux kernel > 4.15.0-1106
}
/// Granular memory statistics for the container, v2 cgroups.
///
/// Exposed in the docker library [here](https://github.com/moby/moby/blob/40d9e2aff130b42ba0f83d5238b9b53184c8ab3b/daemon/daemon_unix.go#L1542).
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
#[allow(missing_docs)]
#[serde(deny_unknown_fields)]
pub struct MemoryStatsStatsV2 {
pub anon: u64,
pub file: u64,
pub kernel_stack: u64,
pub slab: u64,
pub sock: u64,
pub shmem: u64,
pub file_mapped: u64,
pub file_dirty: u64,
pub file_writeback: u64,
pub anon_thp: u64,
pub inactive_anon: u64,
pub active_anon: u64,
pub inactive_file: u64,
pub active_file: u64,
pub unevictable: u64,
pub slab_reclaimable: u64,
pub slab_unreclaimable: u64,
pub pgfault: u64,
pub pgmajfault: u64,
pub workingset_refault: u64,
pub workingset_activate: u64,
pub workingset_nodereclaim: u64,
pub pgrefill: u64,
pub pgscan: u64,
pub pgsteal: u64,
pub pgactivate: u64,
pub pgdeactivate: u64,
pub pglazyfree: u64,
pub pglazyfreed: u64,
pub thp_fault_alloc: u64,
pub thp_collapse_alloc: u64,
}
/// General memory statistics for the container.
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
#[allow(missing_docs)]
pub struct MemoryStats {
pub stats: Option<MemoryStatsStats>,
pub max_usage: Option<u64>,
pub usage: Option<u64>,
pub failcnt: Option<u64>,
pub limit: Option<u64>,
pub commit: Option<u64>,
pub commit_peak: Option<u64>,
pub commitbytes: Option<u64>,
pub commitpeakbytes: Option<u64>,
pub privateworkingset: Option<u64>,
}
/// Process ID statistics for the container.
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
#[allow(missing_docs)]
pub struct PidsStats {
pub current: Option<u64>,
pub limit: Option<u64>,
}
/// I/O statistics for the container.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[allow(missing_docs)]
pub struct BlkioStats {
pub io_service_bytes_recursive: Option<Vec<BlkioStatsEntry>>,
pub io_serviced_recursive: Option<Vec<BlkioStatsEntry>>,
pub io_queue_recursive: Option<Vec<BlkioStatsEntry>>,
pub io_service_time_recursive: Option<Vec<BlkioStatsEntry>>,
pub io_wait_time_recursive: Option<Vec<BlkioStatsEntry>>,
pub io_merged_recursive: Option<Vec<BlkioStatsEntry>>,
pub io_time_recursive: Option<Vec<BlkioStatsEntry>>,
pub sectors_recursive: Option<Vec<BlkioStatsEntry>>,
}
/// File I/O statistics for the container.
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
#[allow(missing_docs)]
pub struct StorageStats {
pub read_count_normalized: Option<u64>,
pub read_size_bytes: Option<u64>,
pub write_count_normalized: Option<u64>,
pub write_size_bytes: Option<u64>,
}
/// Statistics for the container.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[allow(missing_docs)]
pub struct Stats {
#[cfg(feature = "time")]
#[serde(
deserialize_with = "crate::docker::deserialize_rfc3339",
serialize_with = "crate::docker::serialize_rfc3339"
)]
pub read: time::OffsetDateTime,
#[cfg(feature = "time")]
#[serde(
deserialize_with = "crate::docker::deserialize_rfc3339",
serialize_with = "crate::docker::serialize_rfc3339"
)]
pub preread: time::OffsetDateTime,
#[cfg(all(feature = "chrono", not(feature = "time")))]
pub read: chrono::DateTime<chrono::Utc>,
#[cfg(all(feature = "chrono", not(feature = "time")))]
pub preread: chrono::DateTime<chrono::Utc>,
#[cfg(not(any(feature = "chrono", feature = "time")))]
pub read: String,
#[cfg(not(any(feature = "chrono", feature = "time")))]
pub preread: String,
pub num_procs: u32,
pub pids_stats: PidsStats,
pub network: Option<NetworkStats>,
pub networks: Option<HashMap<String, NetworkStats>>,
pub memory_stats: MemoryStats,
pub blkio_stats: BlkioStats,
pub cpu_stats: CPUStats,
pub precpu_stats: CPUStats,
pub storage_stats: StorageStats,
pub name: String,
// Podman incorrectly capitalises the "id" field. See https://github.com/containers/podman/issues/17869
#[serde(alias = "Id")]
pub id: String,
}
/// Network statistics for the container.
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
#[allow(missing_docs)]
pub struct NetworkStats {
pub rx_dropped: u64,
pub rx_bytes: u64,
pub rx_errors: u64,
pub tx_packets: u64,
pub tx_dropped: u64,
pub rx_packets: u64,
pub tx_errors: u64,
pub tx_bytes: u64,
}
/// CPU usage statistics for the container.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[allow(missing_docs)]
pub struct CPUUsage {
pub percpu_usage: Option<Vec<u64>>,
pub usage_in_usermode: u64,
pub total_usage: u64,
pub usage_in_kernelmode: u64,
}
/// CPU throttling statistics.
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
#[allow(missing_docs)]
pub struct ThrottlingData {
pub periods: u64,
pub throttled_periods: u64,
pub throttled_time: u64,
}
/// General CPU statistics for the container.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[allow(missing_docs)]
pub struct CPUStats {
pub cpu_usage: CPUUsage,
pub system_cpu_usage: Option<u64>,
pub online_cpus: Option<u64>,
pub throttling_data: ThrottlingData,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[allow(missing_docs)]
pub struct BlkioStatsEntry {
pub major: u64,
pub minor: u64,
pub op: String,
pub value: u64,
}
/// Parameters used in the [Kill Container API](Docker::kill_container())
///
/// ## Examples
///
/// ```rust
/// use bollard::container::KillContainerOptions;
///
/// KillContainerOptions{
/// signal: "SIGINT",
/// };
/// ```
#[derive(Debug, Clone, Default, PartialEq, Serialize)]
pub struct KillContainerOptions<T>
where
T: Into<String> + Serialize,
{
/// Signal to send to the container as an integer or string (e.g. `SIGINT`)
pub signal: T,
}
/// Configuration for the [Update Container API](Docker::update_container())
///
/// ## Examples
///
/// ```rust
/// use bollard::container::UpdateContainerOptions;
/// use std::default::Default;
///
/// UpdateContainerOptions::<String> {
/// memory: Some(314572800),
/// memory_swap: Some(314572800),
/// ..Default::default()
/// };
/// ```
#[derive(Debug, Clone, Default, PartialEq, Serialize)]
#[serde(rename_all = "PascalCase")]
pub struct UpdateContainerOptions<T>
where
T: Into<String> + Eq + Hash,
{
/// An integer value representing this container's relative CPU weight versus other containers.
#[serde(rename = "CpuShares")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cpu_shares: Option<isize>,
/// Memory limit in bytes.
#[serde(rename = "Memory")]
#[serde(skip_serializing_if = "Option::is_none")]
pub memory: Option<i64>,
/// Path to `cgroups` under which the container's `cgroup` is created. If the path is not absolute, the path is considered to be relative to the `cgroups` path of the init process. Cgroups are created if they do not already exist.
#[serde(rename = "CgroupParent")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cgroup_parent: Option<T>,
/// Block IO weight (relative weight).
#[serde(rename = "BlkioWeight")]
#[serde(skip_serializing_if = "Option::is_none")]
pub blkio_weight: Option<u16>,
/// Block IO weight (relative device weight) in the form `[{\"Path\": \"device_path\", \"Weight\": weight}]`.
#[serde(rename = "BlkioWeightDevice")]
#[serde(skip_serializing_if = "Option::is_none")]
pub blkio_weight_device: Option<Vec<ResourcesBlkioWeightDevice>>,
/// Limit read rate (bytes per second) from a device, in the form `[{\"Path\": \"device_path\", \"Rate\": rate}]`.
#[serde(rename = "BlkioDeviceReadBps")]
#[serde(skip_serializing_if = "Option::is_none")]
pub blkio_device_read_bps: Option<Vec<ThrottleDevice>>,
/// Limit write rate (bytes per second) to a device, in the form `[{\"Path\": \"device_path\", \"Rate\": rate}]`.
#[serde(rename = "BlkioDeviceWriteBps")]
#[serde(skip_serializing_if = "Option::is_none")]
pub blkio_device_write_bps: Option<Vec<ThrottleDevice>>,
/// Limit read rate (IO per second) from a device, in the form `[{\"Path\": \"device_path\", \"Rate\": rate}]`.
#[serde(rename = "BlkioDeviceReadIOps")]
#[serde(skip_serializing_if = "Option::is_none")]
pub blkio_device_read_i_ops: Option<Vec<ThrottleDevice>>,
/// Limit write rate (IO per second) to a device, in the form `[{\"Path\": \"device_path\", \"Rate\": rate}]`.
#[serde(rename = "BlkioDeviceWriteIOps")]
#[serde(skip_serializing_if = "Option::is_none")]
pub blkio_device_write_i_ops: Option<Vec<ThrottleDevice>>,
/// The length of a CPU period in microseconds.
#[serde(rename = "CpuPeriod")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cpu_period: Option<i64>,
/// Microseconds of CPU time that the container can get in a CPU period.
#[serde(rename = "CpuQuota")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cpu_quota: Option<i64>,
/// The length of a CPU real-time period in microseconds. Set to 0 to allocate no time allocated to real-time tasks.
#[serde(rename = "CpuRealtimePeriod")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cpu_realtime_period: Option<i64>,
/// The length of a CPU real-time runtime in microseconds. Set to 0 to allocate no time allocated to real-time tasks.
#[serde(rename = "CpuRealtimeRuntime")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cpu_realtime_runtime: Option<i64>,
/// CPUs in which to allow execution (e.g., `0-3`, `0,1`)
#[serde(rename = "CpusetCpus")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cpuset_cpus: Option<T>,
/// Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems.
#[serde(rename = "CpusetMems")]
#[serde(skip_serializing_if = "Option::is_none")]
pub cpuset_mems: Option<T>,
/// A list of devices to add to the container.
#[serde(rename = "Devices")]
#[serde(skip_serializing_if = "Option::is_none")]
pub devices: Option<Vec<DeviceMapping>>,
/// a list of cgroup rules to apply to the container
#[serde(rename = "DeviceCgroupRules")]
#[serde(skip_serializing_if = "Option::is_none")]
pub device_cgroup_rules: Option<Vec<T>>,
/// a list of requests for devices to be sent to device drivers
#[serde(rename = "DeviceRequests")]
#[serde(skip_serializing_if = "Option::is_none")]
pub device_requests: Option<Vec<DeviceRequest>>,
/// Kernel memory limit in bytes.
#[serde(rename = "KernelMemory")]
#[serde(skip_serializing_if = "Option::is_none")]
pub kernel_memory: Option<i64>,
/// Hard limit for kernel TCP buffer memory (in bytes).
#[serde(rename = "KernelMemoryTCP")]
#[serde(skip_serializing_if = "Option::is_none")]
pub kernel_memory_tcp: Option<i64>,
/// Memory soft limit in bytes.
#[serde(rename = "MemoryReservation")]
#[serde(skip_serializing_if = "Option::is_none")]
pub memory_reservation: Option<i64>,
/// Total memory limit (memory + swap). Set as `-1` to enable unlimited swap.
#[serde(rename = "MemorySwap")]
#[serde(skip_serializing_if = "Option::is_none")]
pub memory_swap: Option<i64>,
/// Tune a container's memory swappiness behavior. Accepts an integer between 0 and 100.
#[serde(rename = "MemorySwappiness")]
#[serde(skip_serializing_if = "Option::is_none")]
pub memory_swappiness: Option<i64>,
/// CPU quota in units of 10<sup>-9</sup> CPUs.
#[serde(rename = "NanoCPUs")]