podman_api/opts/containers.rs
1use crate::models;
2use crate::opts::ImageOpt;
3use containers_api::opts::{Filter, FilterItem};
4use containers_api::{
5 impl_field, impl_filter_func, impl_map_field, impl_opts_builder, impl_str_enum_field,
6 impl_str_field, impl_url_bool_field, impl_url_field, impl_url_str_field, impl_url_vec_field,
7 impl_vec_field,
8};
9use std::fmt;
10
11impl_opts_builder!(url =>
12 /// Adjust the list of returned containers with this options.
13 ContainerList
14);
15
16#[derive(Debug)]
17/// Used to filter listed containers by one of the variants.
18pub enum ContainerListFilter {
19 /// Images that are ancestors.
20 Ancestor(ImageOpt),
21 /// Container ID or name
22 Before(String),
23 /// <port>[/<proto>] or <startport-endport>/[<proto>]
24 Expose(String),
25 /// Containers with exit code of
26 Exited(i32),
27 Health(models::ContainerHealth),
28 /// A container's ID
29 Id(crate::Id),
30 IsTask(bool),
31 /// Container with key label.
32 LabelKey(String),
33 /// Container with key-value label.
34 LabelKeyVal(String, String),
35 /// Container without key label.
36 NoLabelKey(String),
37 /// Container without key-value label.
38 NoLabelKeyVal(String, String),
39 /// A container's name
40 Name(String),
41 /// Network ID or name
42 Network(String),
43 /// Pod ID or name
44 Pod(String),
45 /// <port>[/<proto>] or <startport-endport>/[<proto>]
46 Publish(String),
47 /// Container ID or name
48 Since(String),
49 Status(models::ContainerStatus),
50 /// Volume name or mount point destination
51 Volume(String),
52}
53
54impl Filter for ContainerListFilter {
55 fn query_item(&self) -> FilterItem {
56 use ContainerListFilter::*;
57 match &self {
58 Ancestor(ancestor) => FilterItem::new("ancestor", ancestor.to_string()),
59 Before(container) => FilterItem::new("before", container.clone()),
60 Expose(port) => FilterItem::new("expose", port.clone()),
61 Exited(code) => FilterItem::new("exited", code.to_string()),
62 Health(health) => FilterItem::new("health", health.as_ref().to_string()),
63 Id(id) => FilterItem::new("id", id.to_string()),
64 IsTask(is_task) => FilterItem::new("is-task", is_task.to_string()),
65 LabelKey(key) => FilterItem::new("label", key.clone()),
66 LabelKeyVal(key, val) => FilterItem::new("label", format!("{key}={val}")),
67 NoLabelKey(key) => FilterItem::new("label!", key.clone()),
68 NoLabelKeyVal(key, val) => FilterItem::new("label!", format!("{key}={val}",)),
69 Name(name) => FilterItem::new("name", name.clone()),
70 Network(net) => FilterItem::new("network", net.clone()),
71 Pod(pod) => FilterItem::new("pod", pod.clone()),
72 Publish(port) => FilterItem::new("publish", port.clone()),
73 Since(container) => FilterItem::new("since", container.clone()),
74 Status(status) => FilterItem::new("status", status.as_ref().to_string()),
75 Volume(vol) => FilterItem::new("volume", vol.clone()),
76 }
77 }
78}
79
80impl ContainerListOptsBuilder {
81 impl_url_bool_field!(
82 /// Return all containers. By default, only running containers are shown
83 all => "all"
84 );
85
86 impl_url_field!(
87 /// Return this number of most recently created containers, including non-running ones.
88 limit: usize => "limit"
89 );
90
91 impl_url_bool_field!(
92 /// Return the size of container as fields `size_rw` and `size_root_fs`.
93 size => "size"
94 );
95
96 impl_url_bool_field!(
97 /// Sync container state with OCI runtime
98 sync => "sync"
99 );
100
101 impl_filter_func!(ContainerListFilter);
102}
103
104impl_opts_builder!(url =>
105 /// Adjust the way a container is stopped.
106 ContainerStop
107);
108
109impl ContainerStopOptsBuilder {
110 impl_url_bool_field!(
111 /// Stop all containers
112 all => "all"
113 );
114
115 impl_url_bool_field!(
116 /// Do not return error if container is already stopped
117 ignore => "Ignore"
118 );
119
120 impl_url_field!(
121 /// number of seconds to wait before killing container
122 timeout: usize => "Timeout"
123 );
124}
125
126impl_opts_builder!(url =>
127 /// Adjust the way a container is deleted.
128 ContainerDelete
129);
130
131impl ContainerDeleteOptsBuilder {
132 impl_url_bool_field!(
133 /// Force delete the container.
134 force => "force"
135 );
136
137 impl_url_bool_field!(
138 /// Delete associated volumes.
139 volumes => "v"
140 );
141
142 impl_url_field!(
143 /// Delete associated volumes.
144 timeout: usize => "timeout"
145 );
146}
147
148impl_opts_builder!(url =>
149 /// Adjust the way a container is checkpointed.
150 ContainerCheckpoint
151);
152
153impl ContainerCheckpointOpts {
154 pub(crate) fn for_export(&self) -> Self {
155 let mut new = self.clone();
156 new.params.insert("export", true.to_string());
157 new
158 }
159}
160
161impl ContainerCheckpointOptsBuilder {
162 impl_url_bool_field!(
163 /// Do not include root file-system changes when exporting
164 ignore_root_fs => "ignoreRootFS"
165 );
166
167 impl_url_bool_field!(
168 /// Keep all temporary checkpoint files
169 keep => "keep"
170 );
171
172 impl_url_bool_field!(
173 /// Leave the container running after writing checkpoint to disk
174 leave_running => "leaveRunning"
175 );
176
177 impl_url_bool_field!(
178 /// Add checkpoint statistics to the returned CheckpointReport
179 print_stats => "printStats"
180 );
181
182 impl_url_bool_field!(
183 /// Checkpoint a container with established TCP connections
184 tcp_established => "tcpEstablished"
185 );
186}
187
188impl_opts_builder!(url =>
189 /// Adjust the way a new image is created from a container.
190 ContainerCommit
191);
192
193impl ContainerCommitOpts {
194 pub(crate) fn for_container(&self, container: crate::Id) -> Self {
195 let mut new = self.clone();
196 new.params.insert("container", container.to_string());
197 new
198 }
199}
200
201impl ContainerCommitOptsBuilder {
202 impl_url_str_field!(
203 /// Author of the image
204 author => "author"
205 );
206
207 impl_url_vec_field!(
208 /// Instructions to apply while committing in Dockerfile format (i.e. "CMD=/bin/foo")
209 changes => "changes"
210 );
211
212 impl_url_str_field!(
213 /// Commit message
214 comment => "comment"
215 );
216
217 impl_url_str_field!(
218 /// Format of the image manifest and metadata (default "oci")
219 format => "format"
220 );
221
222 impl_url_bool_field!(
223 /// Pause the container before committing it
224 pause => "pause"
225 );
226
227 impl_url_str_field!(
228 /// The repository name for the created image
229 repo => "repo"
230 );
231
232 impl_url_str_field!(
233 /// Tag name for the created image
234 tag => "tag"
235 );
236}
237
238impl_opts_builder!(url =>
239 /// Adjust how to wait for a container.
240 ContainerWait
241);
242
243impl ContainerWaitOptsBuilder {
244 pub fn conditions(
245 mut self,
246 conditions: impl IntoIterator<Item = models::ContainerStatus>,
247 ) -> Self {
248 let joined = conditions
249 .into_iter()
250 .map(|it| format!("\"{}\"", it.as_ref()))
251 .collect::<Vec<_>>()
252 .join(",");
253 self.params.insert("condition", format!("[{joined}]"));
254 self
255 }
256
257 impl_url_str_field!(
258 /// Time Interval to wait before polling for completion. Example: `250ms`, `2s`
259 interval => "interval"
260 );
261}
262
263impl_opts_builder!(json =>
264 /// Adjust the created container.
265 ContainerCreate
266);
267
268#[derive(Debug, Clone, Copy, PartialEq, Eq)]
269/// Mode used to configure image volume with
270/// [`image_volume_mode`](ContainerCreateOptsBuilder::image_volume_mode).
271#[derive(Default)]
272pub enum ImageVolumeMode {
273 /// Do not create
274 Ignore,
275 /// Create a tmpfs
276 Tmpfs,
277 /// Create as anonymous volumes
278 #[default]
279 Anonymous,
280}
281
282impl AsRef<str> for ImageVolumeMode {
283 fn as_ref(&self) -> &str {
284 match self {
285 ImageVolumeMode::Ignore => "ignore",
286 ImageVolumeMode::Tmpfs => "tmpfs",
287 ImageVolumeMode::Anonymous => "anonymous",
288 }
289 }
290}
291
292impl fmt::Display for ImageVolumeMode {
293 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
294 write!(f, "{}", self.as_ref())
295 }
296}
297
298#[derive(Debug, Clone, Copy, PartialEq, Eq)]
299/// How to handle the `NOTIFY_SOCKET`. Used with
300/// [`sdnotify_mode`](ContainerCreateOptsBuilder::sdnotify_mode).
301pub enum SocketNotifyMode {
302 /// Let the OCI runtime deal with it, advertise conmon's MAINPID.
303 Container,
304 /// Advertise conmon's MAINPID, send READY when started, don't pass to OCI.
305 Conmon,
306 /// Unset `NOTIFY_SOCKET`
307 Ignore,
308}
309
310impl AsRef<str> for SocketNotifyMode {
311 fn as_ref(&self) -> &str {
312 match self {
313 SocketNotifyMode::Container => "container",
314 SocketNotifyMode::Conmon => "conmon",
315 SocketNotifyMode::Ignore => "ignore",
316 }
317 }
318}
319
320impl fmt::Display for SocketNotifyMode {
321 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
322 write!(f, "{}", self.as_ref())
323 }
324}
325
326#[derive(Debug, Clone, Copy, PartialEq, Eq)]
327/// Used with [`ContainerCreateOptsBuilder::seccomp_policy`](ContainerCreateOptsBuilder::seccomp_policy).
328#[derive(Default)]
329pub enum SeccompPolicy {
330 Empty,
331 #[default]
332 Default,
333 Image,
334}
335
336impl AsRef<str> for SeccompPolicy {
337 fn as_ref(&self) -> &str {
338 match self {
339 SeccompPolicy::Empty => "empty",
340 SeccompPolicy::Default => "default",
341 SeccompPolicy::Image => "image",
342 }
343 }
344}
345
346impl fmt::Display for SeccompPolicy {
347 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
348 write!(f, "{}", self.as_ref())
349 }
350}
351
352#[derive(Debug, Clone, Copy, PartialEq, Eq)]
353/// Used with [`ContainerCreateOptsBuilder::systemd`](ContainerCreateOptsBuilder::systemd).
354#[derive(Default)]
355pub enum SystemdEnabled {
356 True,
357 #[default]
358 False,
359 Always,
360}
361
362impl AsRef<str> for SystemdEnabled {
363 fn as_ref(&self) -> &str {
364 match self {
365 SystemdEnabled::True => "true",
366 SystemdEnabled::False => "false",
367 SystemdEnabled::Always => "always",
368 }
369 }
370}
371
372impl fmt::Display for SystemdEnabled {
373 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
374 write!(f, "{}", self.as_ref())
375 }
376}
377
378#[derive(Debug, Clone, Copy, PartialEq, Eq)]
379/// Used with
380/// [`ContainerCreateOptsBuilder::restart_policy`](ContainerCreateOptsBuilder::restart_policy).
381#[derive(Default)]
382pub enum ContainerRestartPolicy {
383 Always,
384 #[default]
385 No,
386 OnFailure,
387 UnlessStopped,
388}
389
390impl AsRef<str> for ContainerRestartPolicy {
391 fn as_ref(&self) -> &str {
392 match self {
393 ContainerRestartPolicy::Always => "always",
394 ContainerRestartPolicy::No => "no",
395 ContainerRestartPolicy::OnFailure => "on-failure",
396 ContainerRestartPolicy::UnlessStopped => "unless-stopped",
397 }
398 }
399}
400
401impl fmt::Display for ContainerRestartPolicy {
402 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
403 write!(f, "{}", self.as_ref())
404 }
405}
406
407impl ContainerCreateOptsBuilder {
408 impl_map_field!(json
409 /// Annotations are key-value options passed into the container runtime that can be used to
410 /// trigger special behavior.
411 annotations => "annotations"
412 );
413
414 impl_str_field!(
415 /// ApparmorProfile is the name of the Apparmor profile the container will use.
416 apparmor_profile => "apparmor_profile"
417 );
418
419 impl_vec_field!(
420 /// Capabilities which will be added to the container. Conflicts with
421 /// [`privileged`](ContainerCreateOptsBuilder::privileged).
422 add_capabilities => "cap_add"
423 );
424
425 impl_vec_field!(
426 /// Capabilities which will be removed from the container. Conflicts with
427 /// [`privileged`](ContainerCreateOptsBuilder::privileged).
428 drop_capabilities => "cap_drop"
429 );
430
431 impl_str_field!(
432 /// Set the container's CGroup parent. If not set, the default for the current cgroup driver
433 /// will be used.
434 cgroup_parent => "cgroup_parent"
435 );
436
437 impl_field!(
438 /// Namespace to use for cgroups.
439 cgroup_namespace: models::Namespace => "cgroupns"
440 );
441
442 impl_str_field!(
443 /// Sets a policy for how cgroups will be created in the container, including the ability
444 /// to disable creation entirely.
445 cgroup_mode => "cgroups_mode"
446 );
447
448 impl_vec_field!(
449 /// Additional set of directories that need to be treated as root directories.
450 /// Standard bind mounts will be mounted into paths relative to these directories.
451 chroot_directories => "chroot_directories"
452 );
453
454 impl_vec_field!(
455 /// Command that the container should run. If not given and Image is specified, this will
456 /// be populated by the image's configuration.
457 command => "command"
458 );
459
460 impl_str_field!(
461 /// A path at which a PID file for Conmon will be placed. If not given, a default location
462 /// will be used.
463 common_pid_file => "common_pid_file"
464 );
465
466 impl_vec_field!(
467 /// The command that was used to create this container. This will be returned when
468 /// inspecting the container.
469 create_command => "containerCreateCommand"
470 );
471
472 impl_field!(
473 /// CPU period of the cpuset
474 cpu_period: u64 => "cpu_period"
475 );
476
477 impl_field!(
478 /// CPU quota of the cpuset
479 cpu_quota: i64 => "cpu_quota"
480 );
481
482 impl_field!(
483 /// Create the working directory if it doesn't exist. If unset, it doesn't create it.
484 create_working_dir: bool => "create_working_dir"
485 );
486
487 impl_vec_field!(
488 /// An array of containers this container depends on. Dependency containers must be started
489 /// before this container. Dependencies can be specified by name or full/partial ID.
490 dependency_containers => "dependencyContainers"
491 );
492
493 impl_vec_field!(
494 /// DeviceCgroupRule are device cgroup rules that allow containers to use additional types of devices.
495 device_cgroup_rule : models::LinuxDeviceCgroup => "device_cgroup_rule"
496 );
497
498 impl_vec_field!(
499 /// Devices are devices that will be added to the container.
500 devices : models::LinuxDevice => "devices"
501 );
502
503 impl_vec_field!(
504 /// A way to ensure your container inherits device specific information from another container.
505 devices_from => "device_from"
506 );
507
508 impl_vec_field!(
509 /// A set of DNS options that will be used in the container's resolv.conf, replacing the host's
510 /// DNS options which are used by default. Conflicts with
511 /// [`use_image_resolv_conf`](ContainerCreateOptsBuilder::use_image_resolv_conf).
512 dns_option => "dns_option"
513 );
514
515 impl_vec_field!(
516 /// A set of DNS search domains that will be used in the container's resolv.conf, replacing
517 /// the host's DNS search domains which are used by default. Conflicts with
518 /// [`use_image_resolv_conf`](ContainerCreateOptsBuilder::use_image_resolv_conf).
519 dns_search => "dns_search"
520 );
521
522 impl_vec_field!(
523 /// A set of DNS servers that will be used in the container's resolv.conf, replacing the
524 /// host's DNS Servers which are used by default. Conflicts with
525 /// [`use_image_resolv_conf`](ContainerCreateOptsBuilder::use_image_resolv_conf).
526 dns_server => "dns_server"
527 );
528
529 impl_vec_field!(
530 /// Container's entrypoint. If not given and Image is specified, this will be populated by
531 /// the image's configuration.
532 entrypoint => "entrypoint"
533 );
534
535 impl_map_field!(json
536 /// A list of environment variables that will be set in the container.
537 env => "env"
538 );
539
540 impl_field!(
541 /// Indicates that the host environment should be added to container.
542 env_host: bool => "env_host"
543 );
544
545 impl_vec_field!(
546 /// Takes the specified environment variables from image and preprocess them before injecting them into the container.
547 envmerge => "envmerge"
548 );
549
550 impl_vec_field!(
551 /// Groups are a list of supplemental groups the container's user will be granted access to.
552 groups => "groups"
553 );
554
555 impl_field!(
556 /// Defines how Podman reacts when a container's health status turns unhealthy.
557 health_check_on_failure_action: i64 => "health_check_on_failure_action"
558 );
559
560 impl_field!(
561 /// Health config which holds configuration settings for the HEALTHCHECK feature, from
562 /// docker/docker/api/types/container.
563 health_config: models::Schema2HealthConfig => "healthconfig"
564 );
565
566 impl_vec_field!(
567 /// The bits have the same definition on all systems, so that information about files can be moved from one system to another portably.
568 /// Not all bits apply to all systems. The only required bit is ModeDir for directories.
569 host_device_list : models::LinuxDevice => "host_device_list"
570 );
571
572 impl_vec_field!(
573 /// A set of hosts which will be added to the container's etc/hosts file. Conflicts with
574 /// [`use_image_hosts`](ContainerCreateOptsBuilder::use_image_hosts).
575 hosts_add => "hostadd"
576 );
577
578 impl_str_field!(
579 /// If not set, the hostname will not be modified (if UtsNS is not private) or will be set
580 /// to the container ID (if UtsNS is private). Conflicts with UtsNS if UtsNS is not set to
581 /// private.
582 hostname => "hostname"
583 );
584
585 impl_vec_field!(
586 /// List of host usernames or UIDs to add to the container etc/passwd file.
587 hostusers => "hostusers"
588 );
589
590 impl_field!(
591 /// Indicates that the http host proxy environment variables should be added to container.
592 http_proxy: bool => "httpproxy"
593 );
594
595 impl_field!(
596 /// Used for specifying how ID mapping should be set up for a layer or container.
597 id_mappings: models::IdMappingOptions => "idmappings"
598 );
599
600 impl_str_field!(
601 /// Image is the image the container will be based on. The image will be used as the
602 /// container's root filesystem, and its environment vars, volumes, and other configuration
603 /// will be applied to the container. Conflicts with [`rootfs`](ContainerCreateOptsBuilder::rootfs).
604 ///
605 /// At least one of [`image`](ContainerCreateOptsBuilder::image) or
606 /// [`rootfs`](ContainerCreateOptsBuilder::rootfs) must be specified.
607 image => "image"
608 );
609
610 impl_str_field!(
611 /// User-specified image architecture
612 image_arch => "image_arch"
613 );
614
615 impl_str_field!(
616 /// User-specified image OS
617 image_os => "image_os"
618 );
619
620 impl_str_field!(
621 /// User-specified image variant
622 image_variant => "image_variant"
623 );
624
625 impl_str_enum_field!(
626 /// Indicates how image volumes will be created. The default if unset is
627 /// [`anonymous`](ImageVolumeMode::Anonymous).
628 image_volume_mode: ImageVolumeMode => "image_volume_mode"
629 );
630
631 impl_vec_field!(
632 /// Image volumes bind-mount a container-image mount into the container.
633 image_volumes : models::ImageVolume => "image_volumes"
634 );
635
636 impl_field!(
637 /// Specifies that an init binary will be mounted into the container, and will be used as
638 /// PID1.
639 init: bool => "init"
640 );
641
642 impl_str_field!(
643 /// Describes if this container is an init container and if so, what type: always or once.
644 init_container_type => "init_container_type"
645 );
646
647 impl_str_field!(
648 /// Specifies the path to the init binary that will be added if
649 /// [`init`](ContainerCreateOptsBuilder::init) is specified above. If not specified, the
650 /// default set in the Libpod config will be used. Ignored if
651 /// [`init`](ContainerCreateOptsBuilder::init) is not set.
652 init_path => "init_path"
653 );
654
655 impl_field!(
656 /// Namespace to use for IPC.
657 ipc_namespace: models::Namespace => "ipcns"
658 );
659
660 impl_map_field!(json
661 /// A list of labels that will be assigned to the container.
662 labels => "labels"
663 );
664
665 impl_field!(
666 /// Logging configuration for the container.
667 log_configuration: models::LogConfig => "log_configuration"
668 );
669
670 impl_field!(
671 /// Container run option that determines if we are validating users/groups before
672 /// running the container.
673 manage_password: bool => "manage_password"
674 );
675
676 impl_vec_field!(
677 /// The path we want to mask in the container. This masks the paths given in addition to
678 /// the default list.
679 mask => "mask"
680 );
681
682 impl_vec_field!(
683 /// Mounts that will be added to the container. These will supersede
684 /// [`image_volumes`](ContainerCreateOptsBuilder::image_volumes) and
685 /// [`volumes_from`](ContainerCreateOptsBuilder::volumes_from) volumes where there
686 /// are conflicts.
687 mounts: models::ContainerMount => "mounts"
688 );
689
690 impl_str_field!(
691 /// The name the container will be given. If no name is provided, one will be randomly
692 /// generated.
693 name => "name"
694 );
695
696 impl_str_field!(
697 /// The libpod namespace the container will be placed in.
698 namespace => "namespace"
699 );
700
701 impl_field!(
702 /// Namespace to use for network.
703 net_namespace: models::Namespace => "netns"
704 );
705
706 impl_map_field!(json
707 /// Additional options for each network.
708 network_options => "network_options"
709 );
710
711 impl_map_field!(json
712 /// Map of networks names or ids that the container should join.
713 /// You can request additional settings for each network, you can set network aliases,
714 /// static ips, static mac address and the network interface name for this container on the specific network.
715 /// If the map is empty and the bridge network mode is set the container will be joined to the default network.
716 networks => "Networks"
717 );
718
719 impl_field!(
720 /// Whether the container will set the no new privileges flag on create, which disables
721 /// gaining additional privileges (e.g. via setuid) in the container.
722 no_new_privilages: bool => "no_new_privilages"
723 );
724
725 impl_str_field!(
726 /// The name of the OCI runtime that will be used to create the container. If not
727 /// specified, the default will be used.
728 oci_runtime => "oci_runtime"
729 );
730
731 impl_field!(
732 /// Adjusts the score used by the OOM killer to determine processes to kill for the container's process.
733 oom_score_adj: i64 => "oom_score_adj"
734 );
735
736 impl_vec_field!(
737 /// Overlay volumes are named volumes that will be added to the container.
738 overlay_volumes : models::OverlayVolume => "overlay_volumes"
739 );
740
741 impl_str_field!(
742 /// Specifies arbitrary data to append to a file.
743 passwd_entry => "passwd_entry"
744 );
745
746 impl_field!(
747 /// Specify the Linux personality syscall input.
748 personality: models::LinuxPersonality => "personality"
749 );
750
751 impl_field!(
752 /// Namespace to use for pids.
753 pid_namespace: models::Namespace => "pidns"
754 );
755
756 impl_str_field!(
757 /// ID of the pod the container should join.
758 pod => "pod"
759 );
760
761 impl_vec_field!(
762 /// Set of ports to map into the container. Only available if NetNS is set to bridge or
763 /// slirp.
764 portmappings: models::PortMapping => "portmappings"
765 );
766
767 impl_field!(
768 /// Whether the container is privileged. Privileged does the following: Adds all devices on
769 /// the system to the container. Adds all capabilities to the container. Disables Seccomp,
770 /// SELinux, and Apparmor confinement. (Though SELinux can be manually re-enabled).
771 privileged: bool => "privileged"
772 );
773
774 impl_vec_field!(
775 /// The options used for the proc mount.
776 procfs_opts => "procfs_opts"
777 );
778
779 impl_field!(
780 /// If set to true the ports specified in the image will be published to random unused ports
781 /// (guaranteed to be above 1024) on the host. This is based on ports set in Expose below,
782 /// and any ports specified by the Image (if one is given). Only available if
783 /// [`net_namespace`](ContainerCreateOptsBuilder::net_namespace) is set to Bridge or Slirp.
784 publish_image_ports: bool => "publish_image_ports"
785 );
786
787 impl_vec_field!(
788 /// Rlimits are POSIX rlimits to apply to the container. Optional.
789 r_limits : models::PosixRlimit => "r_limits"
790 );
791
792 impl_str_field!(
793 /// The user-specified and unprocessed input referring to a local or a remote image.
794 raw_image_name => "raw_image_name"
795 );
796
797 impl_field!(
798 /// If set to true everything will be mounted as read-only.
799 read_only_fs: bool => "read_only_filesystem"
800 );
801
802 impl_field!(
803 /// If set to true the container will be removed upon exitting.
804 remove: bool => "remove"
805 );
806
807 impl_field!(
808 /// Set the container runtime resource contstraints.
809 resource_limits: models::LinuxResources => "resource_limits"
810 );
811
812 impl_str_enum_field!(
813 /// An action which will be taken when the container exits. If not given, the default
814 /// policy, which does nothing, will be used.
815 restart_policy: ContainerRestartPolicy => "restart_policy"
816 );
817
818 impl_field!(
819 /// The number of attempts that will be made to restart the container. Only available
820 /// when [`restart_policy`](ContainerCreateOptsBuilder::restart_policy) is set to `on-failure`.
821 restart_tries: u64 => "restart_tries"
822 );
823
824 impl_str_field!(
825 /// The path to a directory that will be used as the container's root filesystem. No
826 /// modification will be made to the directory, it will be directly mounted into the
827 /// container as root. Conflicts with [`image`](ContainerCreateOptsBuilder::image).
828 ///
829 /// At least one of [`image`](ContainerCreateOptsBuilder::image) or
830 /// [`rootfs`](ContainerCreateOptsBuilder::rootfs) must be specified.
831 rootfs => "rootfs"
832 );
833
834 impl_field!(
835 /// Tells if rootfs is actuall an overlay on top of base path.
836 rootfs_overlay: bool => "rootfs_overlay"
837 );
838
839 impl_str_field!(
840 /// The rootfs propagation mode for the container. If not set, the default of rslave will
841 /// be used.
842 rootfs_propagation => "rootfs_propagation"
843 );
844
845 impl_str_enum_field!(
846 /// Determine how to handle `NOTIFY_SOCKET`.
847 sdnotify_mode: SocketNotifyMode => "sdnotifyMode"
848 );
849
850 impl_str_enum_field!(
851 /// Determines which seccomp profile gets applied the container.
852 seccomp_policy: SeccompPolicy => "seccomp_policy"
853 );
854
855 impl_str_field!(
856 /// The path to a JSON file containing the container's Seccomp profile. If not specified,
857 /// no Seccomp profile will be used.
858 seccomp_profile_path => "seccomp_profile_path"
859 );
860
861 impl_map_field!(json
862 /// A list of secrets that will be set as environment variables.
863 secret_env => "secret_env"
864 );
865
866 impl_vec_field!(
867 /// Secrets are the secrets that will be added to the container.
868 secrets :models::Secret => "secrets"
869 );
870
871 impl_vec_field!(
872 /// The process label the container will use. if SELinux is enabled and this is not
873 /// specified, a label will be automatically generated if not specified.
874 selinux_opts => "selinux_opts"
875 );
876
877 impl_field!(
878 /// The size of the tmpfs to mount in at /dev/shm, in bytes.
879 shm_size: i64 => "shm_size"
880 );
881
882 impl_field!(
883 /// Whether the container should keep it's STDIN open.
884 stdin: bool => "stdin"
885 );
886
887 impl_field!(
888 /// A number describing a process signal.
889 stop_signal: i64 => "stop_signal"
890 );
891
892 impl_field!(
893 /// A timeout between the container's stop signal being sent and SIGKILL being sent. If not
894 /// provided, the default will be used. If 0 is used, stop signal will not be sent, and
895 /// SIGKILL will be sent instead.
896 stop_timeout: u64 => "stop_timeout"
897 );
898
899 impl_map_field!(json
900 /// A list of container's storage options.
901 storage_opts => "storage_opts"
902 );
903
904 impl_map_field!(json
905 /// A list of kernel parameters to set in the container.
906 sysctl => "sysctl"
907 );
908
909 impl_str_enum_field!(
910 systemd: SystemdEnabled => "systemd"
911 );
912
913 impl_field!(
914 /// Whether the container will create a PTY.
915 terminal: bool => "terminal"
916 );
917
918 impl_map_field!(json
919 /// IO read rate limit per cgroup per device, bytes per second
920 throttle_read_bps_device => "throttleReadBpsDevice"
921 );
922
923 impl_map_field!(json
924 ///IO read rate limit per cgroup per device, IO per second
925 throttle_read_iops_device => "throttleReadIOPSDevice"
926 );
927
928 impl_map_field!(json
929 /// IO write rate limit per cgroup per device, bytes per second
930 throttle_write_bps_device => "throttleWriteBpsDevice"
931 );
932
933 impl_map_field!(json
934 /// IO write rate limit per cgroup per device, IO per second
935 throttle_write_iops_device => "throttleWriteIOPSDevice"
936 );
937
938 impl_field!(
939 /// A maximum time in seconds the container will run before main process is sent SIGKILL.
940 /// If 0 is used, signal will not be sent.
941 timeout: u64 => "timeout"
942 );
943
944 impl_str_field!(
945 /// The timezone inside the container. Local means it has the same timezone as the host
946 /// machine.
947 timezone => "timezone"
948 );
949
950 impl_str_field!(
951 /// The umask the init process of the container will be run with.
952 umask => "umask"
953 );
954
955 impl_map_field!(json
956 /// A list of key-value options passed into the container runtime that are used to
957 /// configure cgroup v2.
958 unified => "unified"
959 );
960
961 impl_vec_field!(
962 /// The path we want to unmask in the container. To override all the default paths that are
963 /// masked, set unmask=ALL.
964 unmask => "unmask"
965 );
966
967 impl_vec_field!(
968 /// A list of environment variables to unset if specified in the image or from buildin or
969 /// containers.conf
970 unset_env => "unsetenv"
971 );
972
973 impl_field!(
974 /// If true all environment variables from the image or from buldin or containers.conf will
975 /// get unset.
976 unset_env_all: bool => "unsetenvall"
977 );
978
979 impl_field!(
980 /// Indicates that /etc/hosts should not be managed by Podman, and instead sourced from the image.
981 /// Conflicts with [`hosts_add`](ContainerCreateOptsBuilder::hosts_add).
982 use_image_hosts: bool => "use_image_hosts"
983 );
984
985 impl_field!(
986 /// Indicates that /etc/hosts should not be managed by Podman, and instead sourced from the image.
987 /// Conflicts with [`dns_server`](ContainerCreateOptsBuilder::dns_server),
988 /// [`dns_search`](ContainerCreateOptsBuilder::dns_search),
989 /// [`dns_option`](ContainerCreateOptsBuilder::dns_option).
990 use_image_resolv_conf: bool => "use_image_resolv_conf"
991 );
992
993 impl_str_field!(
994 /// The user the container will be run as. Can be given as a UID or a username; if a username,
995 /// it will be resolved within the container, using the container's /etc/passwd. If unset, the
996 /// container will be run as root.
997 user => "user"
998 );
999
1000 impl_field!(
1001 /// Namespace to use for users.
1002 user_namespace: models::Namespace => "userns"
1003 );
1004
1005 impl_field!(
1006 /// Namespace to use for uts.
1007 uts_namespace: models::Namespace => "utsns"
1008 );
1009
1010 impl_field!(
1011 /// Specifies whether the container storage can be optimized at the cost of not syncing all
1012 /// the dirty files in memory.
1013 volatile: bool => "volatile"
1014 );
1015
1016 impl_vec_field!(
1017 /// Specifies the container volume to use with this container.
1018 volumes: models::NamedVolume => "volumes"
1019 );
1020
1021 impl_vec_field!(
1022 /// Set of containers whose volumes will be added to this container. The name or ID of the
1023 /// container must be provided, and may optionally be followed by a : and then one or more
1024 /// comma-separated options. Valid options are 'ro', 'rw', and 'z'. Options will be used
1025 /// for all volumes sourced from the container.
1026 volumes_from => "volumes_from"
1027 );
1028
1029 impl_field!(
1030 /// Weight per cgroup per device.
1031 weight_device: models::LinuxWeightDevice => "weightDevice"
1032 );
1033
1034 impl_str_field!(
1035 /// Override the container's working directory. If unset, the default, `/`, will be used.
1036 work_dir => "work_dir"
1037 );
1038}
1039
1040impl_opts_builder!(url =>
1041 /// Adjust how to attach to a running container.
1042 ContainerAttach
1043);
1044
1045impl ContainerAttachOpts {
1046 pub(crate) fn stream(&self) -> Self {
1047 let mut new = self.clone();
1048 new.params.insert("stream", true.to_string());
1049 new
1050 }
1051}
1052
1053impl ContainerAttachOptsBuilder {
1054 impl_url_str_field!(
1055 /// Keys to use for detaching from the container.
1056 detach_keys => "detachKeys"
1057 );
1058
1059 impl_url_bool_field!(
1060 /// Attach to container STDERR
1061 stderr => "stderr"
1062 );
1063
1064 impl_url_bool_field!(
1065 /// Attach to container STDIN
1066 stdin => "stdin"
1067 );
1068
1069 impl_url_bool_field!(
1070 /// Attach to container STDOUT
1071 stdout => "stdout"
1072 );
1073}
1074
1075impl_opts_builder!(url =>
1076 /// Adjust how to attach to a running container.
1077 ContainerLogs
1078);
1079
1080impl ContainerLogsOptsBuilder {
1081 impl_url_bool_field!(
1082 /// Keep connection after returning logs.
1083 follow => "follow"
1084 );
1085
1086 impl_url_str_field!(
1087 /// Only return logs since this time, as a UNIX timestamp.
1088 since => "since"
1089 );
1090
1091 impl_url_bool_field!(
1092 /// Return logs from STDERR.
1093 stderr => "stderr"
1094 );
1095
1096 impl_url_bool_field!(
1097 /// Return logs from STDOUT.
1098 stdout => "stdout"
1099 );
1100
1101 impl_url_str_field!(
1102 /// Only return this number of log lines from the end of the logs. Default - `all`
1103 tail => "tail"
1104 );
1105
1106 impl_url_bool_field!(
1107 /// Add timestamps to every log line.
1108 timestamps => "timestamps"
1109 );
1110
1111 impl_url_str_field!(
1112 /// Only return logs before this time, as a UNIX timestamp.
1113 until => "until"
1114 );
1115}
1116
1117impl_opts_builder!(url =>
1118 /// Adjust how container stats are reported.
1119 ContainerStats
1120);
1121
1122impl ContainerStatsOpts {
1123 pub(crate) fn oneshot(&self) -> Self {
1124 let mut new = self.clone();
1125 new.params.insert("stream", false.to_string());
1126 new
1127 }
1128
1129 pub(crate) fn stream(&self) -> Self {
1130 let mut new = self.clone();
1131 new.params.insert("stream", true.to_string());
1132 new
1133 }
1134}
1135
1136impl ContainerStatsOptsBuilder {
1137 impl_url_vec_field!(
1138 /// Names or IDs of containers
1139 containers => "containers"
1140 );
1141
1142 impl_url_field!(
1143 /// Time in seconds between stats reports
1144 interval: usize => "interval"
1145 );
1146}
1147
1148impl_opts_builder!(url =>
1149 /// Adjust how container stats are reported.
1150 ContainerTop
1151);
1152
1153impl ContainerTopOpts {
1154 pub(crate) fn oneshot(&self) -> Self {
1155 let mut new = self.clone();
1156 new.params.insert("stream", false.to_string());
1157 new
1158 }
1159
1160 pub(crate) fn stream(&self) -> Self {
1161 let mut new = self.clone();
1162 new.params.insert("stream", true.to_string());
1163 new
1164 }
1165}
1166
1167impl ContainerTopOptsBuilder {
1168 impl_url_field!(
1169 /// if streaming, delay in seconds between updates. Must be >1. (As of version 4.0)
1170 delay: usize => "delay"
1171 );
1172
1173 impl_url_str_field!(
1174 /// Arguments to pass to ps such as aux. Requires ps(1) to be installed in the container
1175 /// if no ps(1) compatible AIX descriptors are used.
1176 ps_args => "ps_args"
1177 );
1178}
1179
1180#[derive(Debug)]
1181/// Used to filter removed images.
1182pub enum ContainerPruneFilter {
1183 /// Prune containers created before this timestamp. The <timestamp> can be Unix timestamps, date
1184 /// formatted timestamps, or Go duration strings (e.g. 10m, 1h30m) computed relative to the
1185 /// daemon machine’s time.
1186 // #TODO: DateTime
1187 Until(String),
1188 /// Container with key label.
1189 LabelKey(String),
1190 /// Container with key-value label.
1191 LabelKeyVal(String, String),
1192 /// Container without key label.
1193 NoLabelKey(String),
1194 /// Container without key-value label.
1195 NoLabelKeyVal(String, String),
1196}
1197
1198impl Filter for ContainerPruneFilter {
1199 fn query_item(&self) -> FilterItem {
1200 use ContainerPruneFilter::*;
1201 match &self {
1202 Until(until) => FilterItem::new("until", until.to_string()),
1203 LabelKey(key) => FilterItem::new("label", key.clone()),
1204 LabelKeyVal(key, val) => FilterItem::new("label", format!("{key}={val}")),
1205 NoLabelKey(key) => FilterItem::new("label!", key.clone()),
1206 NoLabelKeyVal(key, val) => FilterItem::new("label!", format!("{key}={val}")),
1207 }
1208 }
1209}
1210
1211impl_opts_builder!(url =>
1212 /// Adjust how stopped containers are removed.
1213 ContainerPrune
1214);
1215
1216impl ContainerPruneOptsBuilder {
1217 impl_filter_func!(
1218 /// Filters to process on the prune list.
1219 ContainerPruneFilter
1220 );
1221}
1222
1223impl_opts_builder!(url =>
1224 /// Adjust how a container is restored.
1225 ContainerRestore
1226);
1227
1228impl ContainerRestoreOptsBuilder {
1229 impl_url_bool_field!(
1230 /// Do not include root file-system changes when exporting.
1231 ignore_root_fs => "ignoreRootFS"
1232 );
1233
1234 impl_url_bool_field!(
1235 /// Ignore IP address if set statically.
1236 ignore_static_ip => "ignoreStaticIP"
1237 );
1238
1239 impl_url_bool_field!(
1240 /// Ignore MAC address if set statically.
1241 ignore_static_mac => "ignoreStaticMac"
1242 );
1243
1244 impl_url_bool_field!(
1245 /// Import the restore from a checkpoint tar.gz.
1246 import => "import"
1247 );
1248
1249 impl_url_bool_field!(
1250 /// Keep all temporary checkpoint files.
1251 keep => "keep"
1252 );
1253
1254 impl_url_bool_field!(
1255 /// Leave the container running after writing checkpoint to disk.
1256 leave_running => "leaveRunning"
1257 );
1258
1259 impl_url_str_field!(
1260 /// The name of the container when restored from a tar. can only be used with import.
1261 name => "name"
1262 );
1263
1264 impl_url_str_field!(
1265 /// Pod to restore into.
1266 pod => "pod"
1267 );
1268
1269 impl_url_bool_field!(
1270 /// Add restore statistics to the response.
1271 print_stats => "printStats"
1272 );
1273
1274 impl_url_bool_field!(
1275 /// Checkpoint a container with established TCP connections.
1276 tcp_established => "tcpEstablished"
1277 );
1278}