#[non_exhaustive]pub struct ContainerSpec {
pub name: String,
pub image: String,
pub env: HashMap<String, String>,
pub cmd: Option<Vec<String>>,
pub labels: HashMap<String, String>,
pub restart_policy: RestartPolicy,
pub ports: Vec<PortMapping>,
pub volumes: Vec<VolumeMount>,
pub network: Option<String>,
}Expand description
What to run.
#[non_exhaustive]: build with ContainerSpec::new and the with_*
builders so fields can keep being added without breaking callers.
Debug is hand-written and prints env keys only (see the module
doc on credentials).
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.name: StringDocker container name — must be unique per host.
image: String§env: HashMap<String, String>Environment variables. Not a credential channel: values are
visible to docker inspect. See the module doc.
cmd: Option<Vec<String>>Override the image’s own ENTRYPOINT/CMD. None leaves the
image’s own default command untouched.
labels: HashMap<String, String>§restart_policy: RestartPolicy§ports: Vec<PortMapping>Ports to publish to the host. Empty publishes nothing.
volumes: Vec<VolumeMount>Named volumes to attach. Empty attaches nothing.
network: Option<String>A user-defined Docker network to attach to instead of the default
bridge (HostConfig.NetworkMode); containers on the same
user-defined network resolve each other by container name. None
keeps dockerd’s default. Create it with Lifecycle::ensure_network.
Implementations§
Source§impl ContainerSpec
impl ContainerSpec
pub fn new(name: impl Into<String>, image: impl Into<String>) -> Self
pub fn with_env(self, env: HashMap<String, String>) -> Self
pub fn with_cmd(self, cmd: Vec<String>) -> Self
pub fn with_labels(self, labels: HashMap<String, String>) -> Self
pub fn with_restart_policy(self, policy: RestartPolicy) -> Self
Sourcepub fn with_port(self, port: PortMapping) -> Self
pub fn with_port(self, port: PortMapping) -> Self
Publish one more port.
Sourcepub fn with_ports(self, ports: Vec<PortMapping>) -> Self
pub fn with_ports(self, ports: Vec<PortMapping>) -> Self
Replace the published ports.
Sourcepub fn with_volume(self, volume: VolumeMount) -> Self
pub fn with_volume(self, volume: VolumeMount) -> Self
Attach one more named volume.
Sourcepub fn with_volumes(self, volumes: Vec<VolumeMount>) -> Self
pub fn with_volumes(self, volumes: Vec<VolumeMount>) -> Self
Replace the attached volumes.
Sourcepub fn with_network(self, name: impl Into<String>) -> Self
pub fn with_network(self, name: impl Into<String>) -> Self
Attach to the user-defined network name.
Sourcepub fn validate(&self) -> Result<(), SubstrateError>
pub fn validate(&self) -> Result<(), SubstrateError>
Reject specs dockerd would refuse or that would silently mean
something else, before any Docker call. Called by
Lifecycle::run; public so a caller can fail fast earlier.