pub struct ContainerId(pub String);
Expand description
Container ID returned by docker run
Tuple Fields§
§0: String
Implementations§
Source§impl ContainerId
impl ContainerId
Sourcepub async fn port_mappings(&self) -> Result<Vec<PortMappingInfo>>
pub async fn port_mappings(&self) -> Result<Vec<PortMappingInfo>>
Get port mappings for this container
This queries Docker for the actual mapped ports of the running container.
Useful when using dynamic port allocation (e.g., -p 6379
without specifying host port).
§Example
use docker_wrapper::{DockerCommand, RunCommand};
// Run Redis with dynamic port allocation
let container_id = RunCommand::new("redis:alpine")
.name("my-redis")
.port_dyn(6379) // Dynamic port allocation
.detach()
.rm()
.execute()
.await?;
// Get the actual mapped port
let port_mappings = container_id.port_mappings().await?;
if let Some(mapping) = port_mappings.first() {
println!("Redis is available at {}:{}", mapping.host_ip, mapping.host_port);
}
§Errors
Returns an error if:
- The container doesn’t exist or has been removed
- The Docker daemon is not running
- There’s a communication error with Docker
Sourcepub async fn port_mapping(
&self,
container_port: u16,
) -> Result<Option<PortMappingInfo>>
pub async fn port_mapping( &self, container_port: u16, ) -> Result<Option<PortMappingInfo>>
Get a specific port mapping for this container
§Example
use docker_wrapper::{DockerCommand, RunCommand};
let container_id = RunCommand::new("nginx:alpine")
.port_dyn(80)
.detach()
.rm()
.execute()
.await?;
// Get the mapping for port 80
if let Some(mapping) = container_id.port_mapping(80).await? {
println!("Nginx is available at {}:{}", mapping.host_ip, mapping.host_port);
}
§Errors
Returns an error if:
- The container doesn’t exist or has been removed
- The Docker daemon is not running
- There’s a communication error with Docker
Trait Implementations§
Source§impl Clone for ContainerId
impl Clone for ContainerId
Source§fn clone(&self) -> ContainerId
fn clone(&self) -> ContainerId
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for ContainerId
impl Debug for ContainerId
Source§impl Display for ContainerId
impl Display for ContainerId
Source§impl PartialEq for ContainerId
impl PartialEq for ContainerId
impl Eq for ContainerId
impl StructuralPartialEq for ContainerId
Auto Trait Implementations§
impl Freeze for ContainerId
impl RefUnwindSafe for ContainerId
impl Send for ContainerId
impl Sync for ContainerId
impl Unpin for ContainerId
impl UnwindSafe for ContainerId
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string
, but without panic on OOM.