Docker

Struct Docker 

Source
pub struct Docker { /* private fields */ }
Expand description

Handle to connection to the docker daemon

Implementations§

Source§

impl Docker

Source

pub fn set_credential(&self, credential: Credential)

Source

pub fn connect_with_defaults() -> Result<Docker, DwError>

Connect to the Docker daemon

§Summary

Connect to the Docker daemon using the standard Docker configuration options. This includes:

  • DOCKER_HOST
  • DOCKER_TLS_VERIFY
  • DOCKER_CERT_PATH
  • DOCKER_CONFIG

and we try to interpret these as much like the standard docker client as possible.

Source

pub fn connect_with_unix(addr: &str) -> Result<Docker, DwError>

This ensures that using a fully-qualified path

e.g. unix://…. – works. The unix socket provider expects a Path, so we don’t need scheme.

Source

pub fn connect_with_ssl( _addr: &str, _key: &Path, _cert: &Path, _ca: &Path, ) -> Result<Docker, DwError>

Source

pub fn connect_with_http(addr: &str) -> Result<Docker, DwError>

Connect using unsecured HTTP. This is strongly discouraged everywhere but on Windows when npipe support is not available.

Source

pub async fn list_containers( &self, all: Option<bool>, limit: Option<u64>, size: Option<bool>, filters: ContainerFilters, ) -> Result<Vec<Container>, DwError>

List containers

§API

/containers/json

Source

pub async fn create_container( &self, name: Option<&str>, option: &ContainerCreateOptions, ) -> Result<CreateContainerResponse, DwError>

Create a container

§Summary
  • name - None: auto naming
  • option - create options
§API

POST /containers/create?{name}

Source

pub async fn start_container(&self, id: &str) -> Result<(), DwError>

Start a container

§API

/containers/{id}/start

Source

pub async fn stop_container( &self, id: &str, timeout: Duration, ) -> Result<(), DwError>

Stop a container

§API

/containers/{id}/stop

Source

pub async fn kill_container( &self, id: &str, signal: Signal, ) -> Result<(), DwError>

Kill a container

§API

/containers/{id}/kill

Source

pub async fn rename_container( &self, id: &str, name: &str, ) -> Result<(), DwError>

Rename a container

§Summary

Rename a container specified with id to name.

  • id - ID or name of the container
  • name - new name for the container
§API

/containers/{id}/rename

Source

pub async fn restart_container( &self, id: &str, timeout: Duration, ) -> Result<(), DwError>

Restart a container

§API

/containers/{id}/restart

Source

pub async fn attach_container( &self, id: &str, detachKeys: Option<&str>, logs: bool, stream: bool, stdin: bool, stdout: bool, stderr: bool, ) -> Result<BoxStream<'static, Result<AttachResponseFrame, DwError>>, DwError>

Attach to a container

Attach to a container to read its output or send it input.

§API

/containers/{id}/attach

Source

pub async fn exec_container( &self, id: &str, option: &CreateExecOptions, ) -> Result<CreateExecResponse, DwError>

Create Exec instance for a container

Run a command inside a running container.

§API

/containers/{id}/exec

Source

pub async fn start_exec( &self, id: &str, option: &StartExecOptions, ) -> Result<BoxStream<'static, Result<AttachResponseFrame, DwError>>, DwError>

Start an exec instance

Starts a previously set up exec instance. If detach is true, this endpoint returns immediately after starting the command. Otherwise, it sets up an interactive session with the command.

§API

/exec/{id}/start

Source

pub async fn exec_inspect(&self, id: &str) -> Result<ExecInfo, DwError>

Inspect an exec instance

Return low-level information about an exec instance.

§API

/exec/{id}/json

Source

pub async fn log_container( &self, id: &str, option: &ContainerLogOptions, ) -> Result<BoxStream<'static, Result<String, DwError>>, DwError>

Gets current logs and tails logs from a container

§API

/containers/{id}/logs

Source

pub async fn container_top(&self, container_id: &str) -> Result<Top, DwError>

List processes running inside a container

§API

/containers/{id}/top

Source

pub async fn processes( &self, container_id: &str, ) -> Result<Vec<Process>, DwError>

Source

pub async fn stats( &self, container_id: &str, stream: Option<bool>, oneshot: Option<bool>, ) -> Result<BoxStream<'static, Result<Stats, DwError>>, DwError>

Get containers stats based resource usage

§API

GET /containers/{id}/stats

Source

pub async fn wait_container(&self, id: &str) -> Result<ExitStatus, DwError>

Wait for a container

§API

/containers/{id}/wait

Source

pub async fn remove_container( &self, id: &str, volume: Option<bool>, force: Option<bool>, link: Option<bool>, ) -> Result<(), DwError>

Remove a container

§API

/containers/{id}

Source

pub async fn prune_containers( &self, filters: ContainerPruneFilters, ) -> Result<PrunedContainers, DwError>

Prune unused containers

§API

/containers/prune

Source

pub async fn get_file( &self, id: &str, path: &Path, ) -> Result<BoxStream<'static, Result<Bytes, DwError>>, DwError>

Get an archive of a filesystem resource in a container

§API

/containers/{id}/archive

Source

pub async fn head_file( &self, id: &str, path: &Path, ) -> Result<XDockerContainerPathStat, DwError>

Get information about files in a container

§API

/containers/{id}/archive

Source

pub async fn put_file( &self, id: &str, src: &Path, dst: &Path, noOverwriteDirNonDir: bool, ) -> Result<(), DwError>

Extract an archive of files or folders to a directory in a container

§Summary

Extract given src file into the container specified with id. The input file must be a tar archive with id(no compress), gzip, bzip2 or xz.

  • id : container name or ID
  • src : path to a source file
  • dst : path to a directory in the container to extract the archive’s contents into
§API

/containers/{id}/archive

Source

pub async fn build_image( &self, options: ContainerBuildOptions, tar_path: &Path, ) -> Result<BoxStream<'static, Result<DockerResponse, DwError>>, DwError>

Build an image from a tar archive with a Dockerfile in it.

§API

/build?

Source

pub async fn create_image( &self, image: &str, tag: &str, ) -> Result<BoxStream<'static, Result<DockerResponse, DwError>>, DwError>

Create an image by pulling it from registry

§API

/images/create?fromImage={image}&tag={tag}

§NOTE

When control returns from this function, creating job may not have been completed. For waiting the completion of the job, consuming response like create_image("hello-world", "linux").map(|r| r.for_each(|_| ()));.

§TODO
  • Typing result iterator like image::ImageStatus.
  • Generalize input parameters
Source

pub async fn inspect_image(&self, name: &str) -> Result<Image, DwError>

Inspect an image

§API

/images/{name}/json

Source

pub async fn push_image(&self, name: &str, tag: &str) -> Result<(), DwError>

Push an image

§NOTE

For pushing an image to non default registry, add registry id to prefix of the image name like <registry>/<image> . But the name of the local cache image is <image>:<tag> .

§API

/images/{name}/push

Source

pub async fn remove_image( &self, name: &str, force: Option<bool>, noprune: Option<bool>, ) -> Result<Vec<RemovedImage>, DwError>

Remove an image

§API

/images/{name}

Source

pub async fn prune_image(&self, dangling: bool) -> Result<PrunedImages, DwError>

Delete unused images

§API

/images/prune

Source

pub async fn history_image( &self, name: &str, ) -> Result<Vec<ImageLayer>, DwError>

History of an image

§API

/images/{name}/history

Source

pub async fn images(&self, all: bool) -> Result<Vec<SummaryImage>, DwError>

List images

§API

/images/json

Source

pub async fn search_images( &self, term: &str, limit: Option<u64>, filters: ImageFilters, ) -> Result<Vec<FoundImage>, DwError>

Search for an image on Docker Hub.

§API

/images/search

Source

pub async fn export_image( &self, name: &str, ) -> Result<BoxStream<'static, Result<Bytes, DwError>>, DwError>

Get a tarball containing all images and metadata for a repository

§API

/images/{name}/get

Source

pub async fn load_image( &self, quiet: bool, path: &Path, ) -> Result<ImageId, DwError>

Import images

§Summary

Load a set of images and tags into a repository

§API

/images/load

Source

pub async fn auth( &self, username: &str, password: &str, email: &str, serveraddress: &str, ) -> Result<AuthToken, DwError>

Check auth configuration

§API

/auth

§NOTE

In some cases, docker daemon returns an empty token with 200 Ok. The empty token could not be used for authenticating users.

Source

pub async fn system_info(&self) -> Result<SystemInfo, DwError>

Get system information

§API

/info

Source

pub async fn container_info( &self, container_id: &str, ) -> Result<ContainerInfo, DwError>

Inspect about a container

§API

/containers/{id}/json

Source

pub async fn filesystem_changes( &self, container_id: &str, ) -> Result<Vec<FilesystemChange>, DwError>

Get changes on a container’s filesystem.

(This is the same as docker container diff command.)

§API

/containers/{id}/changes

Source

pub async fn export_container( &self, container_id: &str, ) -> Result<BoxStream<'static, Result<Bytes, DwError>>, DwError>

Export a container

§Summary

Returns a pointer to tar archive stream.

§API

/containers/{id}/export

Source

pub async fn ping(&self) -> Result<(), DwError>

Test if the server is accessible

§API

/_ping

Source

pub async fn version(&self) -> Result<Version, DwError>

Get version and various information

§API

/version

Source

pub async fn events( &self, since: Option<u64>, until: Option<u64>, filters: Option<EventFilters>, ) -> Result<BoxStream<'static, Result<EventResponse, DwError>>, DwError>

Get monitor events

§API

/events

Source

pub async fn list_networks( &self, filters: ListNetworkFilters, ) -> Result<Vec<Network>, DwError>

List networks

§API

/networks

Source

pub async fn inspect_network( &self, id: &str, verbose: Option<bool>, scope: Option<&str>, ) -> Result<Network, DwError>

Inspect a network

§API

/networks/{id}

Source

pub async fn remove_network(&self, id: &str) -> Result<(), DwError>

Remove a network

§API

/networks/{id}

Source

pub async fn create_network( &self, option: &NetworkCreateOptions, ) -> Result<CreateNetworkResponse, DwError>

Create a network

§API

/networks/create

Source

pub async fn connect_network( &self, id: &str, option: &NetworkConnectOptions, ) -> Result<(), DwError>

Connect a container to a network

§API

/networks/{id}/connect

Source

pub async fn disconnect_network( &self, id: &str, option: &NetworkDisconnectOptions, ) -> Result<(), DwError>

Disconnect a container from a network

§API

/networks/{id}/disconnect

Source

pub async fn prune_networks( &self, filters: PruneNetworkFilters, ) -> Result<PruneNetworkResponse, DwError>

Delete unused networks

§API

/networks/prune

Trait Implementations§

Source§

impl Clone for Docker

Source§

fn clone(&self) -> Docker

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Docker

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Docker

§

impl !RefUnwindSafe for Docker

§

impl Send for Docker

§

impl Sync for Docker

§

impl Unpin for Docker

§

impl !UnwindSafe for Docker

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more