docker_client_async/types/
host.rs

1/*
2 * Copyright 2020 Damian Peckett <damian@pecke.tt>.
3 * Copyright 2013-2018 Docker, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18use crate::types::blkio::{ThrottleDevice, WeightDevice};
19use crate::types::mounts::Mount;
20use crate::types::port::PortMap;
21use derive_builder::Builder;
22use serde::{Deserialize, Serialize};
23use std::collections::HashMap;
24
25/// HostConfig the non-portable Config structure of a container.
26/// Here, "non-portable" means "dependent of the host we are running on".
27/// Portable information *should* appear in Config.
28#[derive(Clone, Debug, Default, Deserialize, Serialize, Builder)]
29#[builder(default, setter(into))]
30pub struct HostConfig {
31    // Applicable to all platforms.
32    /// List of volume bindings for this container.
33    #[serde(rename = "Binds")]
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub binds: Option<Vec<String>>,
36    /// File (path) where the containerId is written.
37    #[serde(rename = "ContainerIDFile")]
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub container_id_file: Option<String>,
40    /// Configuration of the logs for this container.
41    #[serde(rename = "LogConfig")]
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub log_config: Option<LogConfig>,
44    /// Network mode to use for the container.
45    #[serde(rename = "NetworkMode")]
46    #[serde(skip_serializing_if = "Option::is_none")]
47    pub network_mode: Option<String>,
48    /// Port mapping between the exposed port (container) and the host.
49    #[serde(rename = "PortBindings")]
50    #[serde(skip_serializing_if = "Option::is_none")]
51    pub port_bindings: Option<PortMap>,
52    /// Restart policy to be used for the container.
53    #[serde(rename = "RestartPolicy")]
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub restart_policy: Option<RestartPolicy>,
56    /// Automatically remove container when it exits.
57    #[serde(rename = "AutoRemove")]
58    #[serde(skip_serializing_if = "Option::is_none")]
59    pub auto_remove: Option<bool>,
60    /// Name of the volume driver used to mount volumes.
61    #[serde(rename = "VolumeDriver")]
62    #[serde(skip_serializing_if = "Option::is_none")]
63    pub volume_driver: Option<String>,
64    /// List of volumes to take from other container.
65    #[serde(rename = "VolumesFrom")]
66    #[serde(skip_serializing_if = "Option::is_none")]
67    pub volumes_from: Option<Vec<String>>,
68
69    // Applicable to UNIX platforms.
70    /// List of kernel capabilities to add to the container.
71    #[serde(rename = "CapAdd")]
72    #[serde(skip_serializing_if = "Option::is_none")]
73    pub cap_add: Option<Vec<String>>,
74    /// List of kernel capabilities to remove from the container.
75    #[serde(rename = "CapDrop")]
76    #[serde(skip_serializing_if = "Option::is_none")]
77    pub cap_drop: Option<Vec<String>>,
78    /// List of kernel capabilities to be available for container (this overrides the default set).
79    #[serde(rename = "Capabilities")]
80    #[serde(skip_serializing_if = "Option::is_none")]
81    pub capabilities: Option<Vec<String>>,
82    /// Cgroup namespace mode to use for the container.
83    #[serde(rename = "CgroupnsMode")]
84    #[serde(skip_serializing_if = "Option::is_none")]
85    pub cgroup_ns_mode: Option<String>,
86    /// List of DNS server to lookup.
87    #[serde(rename = "Dns")]
88    #[serde(skip_serializing_if = "Option::is_none")]
89    pub dns: Option<Vec<String>>,
90    /// List of DNSOption to look for.
91    #[serde(rename = "DnsOptions")]
92    #[serde(skip_serializing_if = "Option::is_none")]
93    pub dns_options: Option<Vec<String>>,
94    /// List of DNSSearch to look for.
95    #[serde(rename = "DnsSearch")]
96    #[serde(skip_serializing_if = "Option::is_none")]
97    pub dns_search: Option<Vec<String>>,
98    /// List of extra hosts.
99    #[serde(rename = "ExtraHosts")]
100    #[serde(skip_serializing_if = "Option::is_none")]
101    pub extra_hosts: Option<Vec<String>>,
102    /// List of additional groups that the container process will run as.
103    #[serde(rename = "GroupAdd")]
104    #[serde(skip_serializing_if = "Option::is_none")]
105    pub group_add: Option<Vec<String>>,
106    /// IPC namespace to use for the container.
107    #[serde(rename = "IpcMode")]
108    #[serde(skip_serializing_if = "Option::is_none")]
109    pub ipc_mode: Option<String>,
110    /// Cgroup to use for the container.
111    #[serde(rename = "Cgroup")]
112    #[serde(skip_serializing_if = "Option::is_none")]
113    pub cgroup: Option<String>,
114    /// List of links (in the name:alias form).
115    #[serde(rename = "Links")]
116    #[serde(skip_serializing_if = "Option::is_none")]
117    pub links: Option<Vec<String>>,
118    /// Container preference for OOM-killing.
119    #[serde(rename = "OomScoreAdj")]
120    #[serde(skip_serializing_if = "Option::is_none")]
121    pub oom_score_adj: Option<i32>,
122    /// PID namespace to use for the container.
123    #[serde(rename = "PidMode")]
124    #[serde(skip_serializing_if = "Option::is_none")]
125    pub pid_mode: Option<String>,
126    /// Is the container in privileged mode.
127    #[serde(rename = "Privileged")]
128    #[serde(skip_serializing_if = "Option::is_none")]
129    pub privileged: Option<bool>,
130    /// Should docker publish all exposed port for the container.
131    #[serde(rename = "PublishAllPorts")]
132    #[serde(skip_serializing_if = "Option::is_none")]
133    pub publish_all_ports: Option<bool>,
134    /// Is the container root filesystem in read-only.
135    #[serde(rename = "ReadonlyRootfs")]
136    #[serde(skip_serializing_if = "Option::is_none")]
137    pub readonly_rootfs: Option<bool>,
138    /// List of string values to customize labels for MLS systems, such as SELinux.
139    #[serde(rename = "SecurityOpt")]
140    #[serde(skip_serializing_if = "Option::is_none")]
141    pub security_opt: Option<Vec<String>>,
142    /// Storage driver options per container.
143    #[serde(rename = "StorageOpt")]
144    #[serde(skip_serializing_if = "Option::is_none")]
145    pub storage_opt: Option<HashMap<String, String>>,
146    /// List of tmpfs (mounts) used for the container.
147    #[serde(rename = "Tmpfs")]
148    #[serde(skip_serializing_if = "Option::is_none")]
149    pub tmpfs: Option<HashMap<String, String>>,
150    /// UTS namespace to use for the container.
151    #[serde(rename = "UTSMode")]
152    #[serde(skip_serializing_if = "Option::is_none")]
153    pub uts_mode: Option<String>,
154    /// The user namespace to use for the container.
155    #[serde(rename = "UsernsMode")]
156    #[serde(skip_serializing_if = "Option::is_none")]
157    pub user_ns_mode: Option<String>,
158    /// Total shm memory usage.
159    #[serde(rename = "ShmSize")]
160    #[serde(skip_serializing_if = "Option::is_none")]
161    pub shm_size: Option<i64>,
162    /// List of Namespaced sysctls used for the container.
163    #[serde(rename = "Sysctls")]
164    #[serde(skip_serializing_if = "Option::is_none")]
165    pub sysctls: Option<HashMap<String, String>>,
166    /// Runtime to use with this container.
167    #[serde(rename = "Runtime")]
168    #[serde(skip_serializing_if = "Option::is_none")]
169    pub runtime: Option<String>,
170
171    // Applicable to Windows.
172    /// Initial console size (height,width).
173    #[serde(rename = "ConsoleSize")]
174    #[serde(skip_serializing_if = "Option::is_none")]
175    pub console_size: Option<[u32; 2]>,
176    /// Isolation technology of the container (e.g. default, hyperv).
177    #[serde(rename = "Isolation")]
178    #[serde(skip_serializing_if = "Option::is_none")]
179    pub isolation: Option<String>,
180
181    // Applicable to all platforms.
182    /// CPU shares (relative weight vs. other containers).
183    #[serde(rename = "CpuShares")]
184    #[serde(skip_serializing_if = "Option::is_none")]
185    pub cpu_shares: Option<i64>,
186    /// Memory limit (in bytes).
187    #[serde(rename = "Memory")]
188    #[serde(skip_serializing_if = "Option::is_none")]
189    pub memory: Option<i64>,
190    /// CPU quota in units of 10<sup>-9</sup> CPUs.
191    #[serde(rename = "NanoCPUs")]
192    #[serde(skip_serializing_if = "Option::is_none")]
193    pub nano_cpus: Option<i64>,
194
195    // Applicable to UNIX platforms.
196    /// Parent cgroup.
197    #[serde(rename = "CgroupParent")]
198    #[serde(skip_serializing_if = "Option::is_none")]
199    pub cgroup_parent: Option<String>,
200    /// Block IO weight (relative weight vs. other containers).
201    #[serde(rename = "BlkioWeight")]
202    #[serde(skip_serializing_if = "Option::is_none")]
203    pub blkio_weight: Option<u16>,
204    #[serde(rename = "BlkioWeightDevice")]
205    #[serde(skip_serializing_if = "Option::is_none")]
206    pub blkio_weight_device: Option<Vec<WeightDevice>>,
207    #[serde(rename = "BlkioDeviceReadBps")]
208    #[serde(skip_serializing_if = "Option::is_none")]
209    pub blkio_device_read_bps: Option<Vec<ThrottleDevice>>,
210    #[serde(rename = "BlkioDeviceWriteBps")]
211    #[serde(skip_serializing_if = "Option::is_none")]
212    pub blkio_device_write_bps: Option<Vec<ThrottleDevice>>,
213    #[serde(rename = "BlkioDeviceReadIOps")]
214    #[serde(skip_serializing_if = "Option::is_none")]
215    pub blkio_device_read_iops: Option<Vec<ThrottleDevice>>,
216    #[serde(rename = "BlkioDeviceWriteIOps")]
217    #[serde(skip_serializing_if = "Option::is_none")]
218    pub blkio_device_write_iops: Option<Vec<ThrottleDevice>>,
219    /// CPU CFS (Completely Fair Scheduler) period.
220    #[serde(rename = "CpuPeriod")]
221    #[serde(skip_serializing_if = "Option::is_none")]
222    pub cpu_period: Option<i64>,
223    /// CPU CFS (Completely Fair Scheduler) quota.
224    #[serde(rename = "CpuQuota")]
225    #[serde(skip_serializing_if = "Option::is_none")]
226    pub cpu_quota: Option<i64>,
227    /// CPU real-time period.
228    #[serde(rename = "CpuRealtimePeriod")]
229    #[serde(skip_serializing_if = "Option::is_none")]
230    pub cpu_realtime_period: Option<i64>,
231    /// CPU real-time runtime.
232    #[serde(rename = "CpuRealtimeRuntime")]
233    #[serde(skip_serializing_if = "Option::is_none")]
234    pub cpu_realtime_runtime: Option<i64>,
235    /// CpusetCpus 0-2, 0,1.
236    #[serde(rename = "CpusetCpus")]
237    #[serde(skip_serializing_if = "Option::is_none")]
238    pub cpuset_cpus: Option<String>,
239    /// CpusetMems 0-2, 0,1.
240    #[serde(rename = "CpusetMems")]
241    #[serde(skip_serializing_if = "Option::is_none")]
242    pub cpuset_mems: Option<String>,
243    /// List of devices to map inside the container.
244    #[serde(rename = "Devices")]
245    #[serde(skip_serializing_if = "Option::is_none")]
246    pub devices: Option<Vec<DeviceMapping>>,
247    /// List of rule to be added to the device cgroup.
248    #[serde(rename = "DeviceCgroupRules")]
249    #[serde(skip_serializing_if = "Option::is_none")]
250    pub device_cgroup_rules: Option<Vec<String>>,
251    /// List of device requests for device drivers.
252    #[serde(rename = "DeviceRequests")]
253    #[serde(skip_serializing_if = "Option::is_none")]
254    pub device_requests: Option<Vec<DeviceRequest>>,
255    /// Kernel memory limit (in bytes).
256    #[serde(rename = "KernelMemory")]
257    #[serde(skip_serializing_if = "Option::is_none")]
258    pub kernel_memory: Option<i64>,
259    /// Hard limit for kernel TCP buffer memory (in bytes).
260    #[serde(rename = "KernelMemoryTCP")]
261    #[serde(skip_serializing_if = "Option::is_none")]
262    pub kernel_memory_tcp: Option<i64>,
263    /// Memory soft limit (in bytes).
264    #[serde(rename = "MemoryReservation")]
265    #[serde(skip_serializing_if = "Option::is_none")]
266    pub memory_reservation: Option<i64>,
267    /// Total memory usage (memory + swap); set `-1` to enable unlimited swap.
268    #[serde(rename = "MemorySwap")]
269    #[serde(skip_serializing_if = "Option::is_none")]
270    pub memory_swap: Option<i64>,
271    /// Tuning container memory swappiness behaviour.
272    #[serde(rename = "MemorySwappiness")]
273    #[serde(skip_serializing_if = "Option::is_none")]
274    pub memory_swappiness: Option<i64>,
275    /// Whether to disable OOM Killer or not.
276    #[serde(rename = "OomKillDisable")]
277    #[serde(skip_serializing_if = "Option::is_none")]
278    pub oom_kill_disable: Option<bool>,
279    /// Setting PIDs limit for a container; Set `0` or `-1` for unlimited, or `null` to not change.
280    #[serde(rename = "PidsLimit")]
281    #[serde(skip_serializing_if = "Option::is_none")]
282    pub pids_limit: Option<i64>,
283    /// List of ulimits to be set in the container.
284    #[serde(rename = "Ulimits")]
285    #[serde(skip_serializing_if = "Option::is_none")]
286    pub ulimits: Option<Vec<Ulimit>>,
287
288    // Applicable to Windows.
289    /// CPU count.
290    #[serde(rename = "CpuCount")]
291    #[serde(skip_serializing_if = "Option::is_none")]
292    pub cpu_count: Option<i64>,
293    /// CPU percent.
294    #[serde(rename = "CpuPercent")]
295    #[serde(skip_serializing_if = "Option::is_none")]
296    pub cpu_percent: Option<i64>,
297    /// Maximum IOps for the container system drive.
298    #[serde(rename = "IOMaximumIOps")]
299    #[serde(skip_serializing_if = "Option::is_none")]
300    pub io_maximum_iops: Option<u64>,
301    /// Maximum IO in bytes per second for the container system drive.
302    #[serde(rename = "IOMaximumBandwidth")]
303    #[serde(skip_serializing_if = "Option::is_none")]
304    pub io_maximum_bandwidth: Option<u64>,
305    /// Mounts specs used by the container.
306    #[serde(rename = "Mounts")]
307    #[serde(skip_serializing_if = "Option::is_none")]
308    pub mounts: Option<Vec<Mount>>,
309    /// MaskedPaths is the list of paths to be masked inside the container
310    /// (this overrides the default set of paths).
311    #[serde(rename = "MaskedPaths")]
312    #[serde(skip_serializing_if = "Option::is_none")]
313    pub masked_paths: Option<Vec<String>>,
314    /// ReadonlyPaths is the list of paths to be set as read-only inside
315    /// the container (this overrides the default set of paths).
316    #[serde(rename = "ReadonlyPaths")]
317    #[serde(skip_serializing_if = "Option::is_none")]
318    pub readonly_paths: Option<Vec<String>>,
319    /// Run a custom init inside the container, if null, use the daemon's configured settings.
320    #[serde(rename = "Init")]
321    #[serde(skip_serializing_if = "Option::is_none")]
322    pub init: Option<bool>,
323}
324
325/// LogConfig represents the logging configuration of the container.
326#[derive(Clone, Debug, Default, Deserialize, Serialize, Builder)]
327#[builder(default, setter(into))]
328pub struct LogConfig {
329    #[serde(rename = "Type")]
330    #[serde(skip_serializing_if = "Option::is_none")]
331    pub log_type: Option<String>,
332    #[serde(rename = "Config")]
333    #[serde(skip_serializing_if = "Option::is_none")]
334    pub config: Option<HashMap<String, String>>,
335}
336
337/// RestartPolicy represents the restart policies of the container.
338#[derive(Clone, Debug, Default, Deserialize, Serialize, Builder)]
339#[builder(default, setter(into))]
340pub struct RestartPolicy {
341    #[serde(rename = "Name")]
342    #[serde(skip_serializing_if = "Option::is_none")]
343    pub name: Option<String>,
344    #[serde(rename = "MaximumRetryCount")]
345    #[serde(skip_serializing_if = "Option::is_none")]
346    pub maximum_retry_count: Option<i32>,
347}
348
349/// DeviceMapping represents the device mapping between the host and the container.
350#[derive(Clone, Debug, Default, Deserialize, Serialize, Builder)]
351#[builder(default, setter(into))]
352pub struct DeviceMapping {
353    #[serde(rename = "PathOnHost")]
354    #[serde(skip_serializing_if = "Option::is_none")]
355    pub path_on_host: Option<String>,
356    #[serde(rename = "PathInContainer")]
357    #[serde(skip_serializing_if = "Option::is_none")]
358    pub path_in_container: Option<String>,
359    #[serde(rename = "CgroupPermissions")]
360    #[serde(skip_serializing_if = "Option::is_none")]
361    pub cgroup_permissions: Option<String>,
362}
363
364/// DeviceRequest represents a request for devices from a device driver.
365/// Used by GPU device drivers.
366#[derive(Clone, Debug, Default, Deserialize, Serialize, Builder)]
367#[builder(default, setter(into))]
368pub struct DeviceRequest {
369    /// Name of device driver.
370    #[serde(rename = "Driver")]
371    #[serde(skip_serializing_if = "Option::is_none")]
372    pub driver: Option<String>,
373    /// Number of devices to request (-1 = All).
374    #[serde(rename = "Count")]
375    #[serde(skip_serializing_if = "Option::is_none")]
376    pub count: Option<i32>,
377    /// List of device IDs as recognizable by the device driver.
378    #[serde(rename = "DeviceIDs")]
379    #[serde(skip_serializing_if = "Option::is_none")]
380    pub device_ids: Option<Vec<String>>,
381    /// An OR list of AND lists of device capabilities (e.g. "gpu").
382    #[serde(rename = "Capabilities")]
383    #[serde(skip_serializing_if = "Option::is_none")]
384    pub capabilities: Option<Vec<Vec<String>>>,
385    /// Options to pass onto the device driver.
386    #[serde(rename = "Options")]
387    #[serde(skip_serializing_if = "Option::is_none")]
388    pub options: Option<HashMap<String, String>>,
389}
390
391/// Ulimit is a human friendly version of Rlimit.
392#[derive(Clone, Debug, Default, Deserialize, Serialize, Builder)]
393#[builder(default, setter(into))]
394pub struct Ulimit {
395    #[serde(rename = "Name")]
396    #[serde(skip_serializing_if = "Option::is_none")]
397    pub name: Option<String>,
398    #[serde(rename = "Hard")]
399    #[serde(skip_serializing_if = "Option::is_none")]
400    pub hard: Option<i64>,
401    #[serde(rename = "Soft")]
402    #[serde(skip_serializing_if = "Option::is_none")]
403    pub soft: Option<i64>,
404}