docker-api-rs icon indicating copy to clipboard operation
docker-api-rs copied to clipboard

Missing Stop and Start example for Containers

Open Darrilla opened this issue 3 years ago • 1 comments

I have been trying to add stop and start commands, but no luck so far. Can someone provide an example of how to do this?

Darrilla avatar Oct 17 '22 17:10 Darrilla

There already is support for stopping and starting a container. Here is a short example:

use docker_api::Docker;

let docker = Docker::unix("/var/run/docker.sock");
let containers = docker.containers();

let container = containers.get("<container-id-or-name>");
container.start().await;
// ... Do something with the container ...
container.stop(None).await;
// The None here is an optional duration to wait for the container to close

I just noticed that this actions are missing from the example file https://github.com/vv9k/docker-api-rs/blob/master/examples/container.rs so it I'll rename this issue to track the addition of those actions to the file.

vv9k avatar Oct 18 '22 06:10 vv9k