Module Docker.Container

type port = {
priv : int;(*

Private port number.

*)
pub : int;(*

Public port number.

*)
typ : string;(*

Type, e.g., "tcp".

*)
}
type id = string
type id_or_name = string
type t = {
id : id;(*

Identifier of the container.

*)
names : string list;(*

Names given to the container.

*)
image : string;(*

Name of the image used to create the container.

*)
command : string;(*

Command passed to the container.

*)
created : float;(*

Unix time of creation.

*)
status : string;(*

Human readable status.

*)
ports : port list;
size_rw : int option;
size_root_fs : int option;
}
type bind =
| Vol of string(*

create a new volume for the container

*)
| Mount of string * string(*

Mount(host_path, container_path) bind-mount a host path into the container. A relative host_path will be interpreted as relative to the current working directory (at the time of the function calling this binding). container_path must be an absolute path inside the container.

*)
| Mount_ro of string * string(*

As Mount but make the bind-mount read-only inside the container.

*)
val list : ?addr:Unix.sockaddr -> ?all:bool -> ?limit:int -> ?size:bool -> ?before:id_or_name -> ?exited:int list -> ?health:[ `Starting | `Healthy | `Unhealthy | `None ] list -> ?name:string list -> ?since:id_or_name -> ?status: [ `Created | `Restarting | `Running | `Removing | `Paused | `Exited | `Dead ] list -> ?volume:string -> unit -> t list

list () lists running containers (or all containers if ~all is set to true).

  • parameter all

    Show all containers. Only running containers are shown by default (i.e., this defaults to false).

  • parameter limit

    Return this number of most recently created containers, including non-running ones.

  • parameter size

    Return the size of container as fields size_rw and size_root_fs.

    The following options set filters on the returned container list: before, exited (containers with exit code given by exited), health, name, since, status, volume.

type host_config = {
cpu_shares : int;(*

Represents this container's relative CPU weight versus other containers. Non-positive values are ignored.

*)
memory : int;(*

Memory limit in bytes.

*)
cgroup_parent : string;(*

Path to cgroups under which the container's cgroup is created. If the path is not absolute, the path is considered to be relative to the cgroups path of the init process. Cgroups are created if they do not already exist.

*)
blk_io_weight : int;(*

Block IO weight (relative weight). Values outside 0 .. 1000 do not set this field.

*)
cpu_period : int;(*

The length of a CPU period in microseconds. Non-positive values do not set this field.

*)
memory_swap : int;(*

Total memory limit (memory + swap). Set as -1 to enable unlimited swap.

*)
binds : bind list;(*

A list of volume bindings for this container.

*)
network_mode : string;(*

Network mode to use for this container. Supported standard values are: bridge, host, none, and container:<name|id>. Any other value is taken as a custom network's name to which this container should connect to.

*)
policy : [ `None | `Auto_remove | `Restart_always | `Restart_unless_stopped | `Restart_on_failure of int ];(*

The behavior to apply when the container exits. The default is not to restart and not to remove the container (`None). An ever increasing delay (double the previous delay, starting at 100ms) is added before each restart to prevent flooding the server.

  • `Auto_remove Automatically remove the container when the container's process exits.
  • `Restart_always Always restart.
  • `Restart_unless_stopped Restart always except when the user has manually stopped the container.
  • `Restart_on_failure n Restart only when the container exit code is non-zero. The number n says how many times to retry before giving up.
*)
}
val host : ?cpu_shares:int -> ?memory:int -> ?cgroup_parent:string -> ?blk_io_weight:int -> ?cpu_period:int -> ?memory_swap:int -> ?binds:bind list -> ?network_mode:string -> ?policy: [ `Auto_remove | `None | `Restart_always | `Restart_on_failure of int | `Restart_unless_stopped ] -> unit -> host_config

Return the default host configuration changed according to which optional labels were set.

val create : ?addr:Unix.sockaddr -> ?hostname:string -> ?domainname:string -> ?user:string -> ?stdin:bool -> ?stdout:bool -> ?stderr:bool -> ?open_stdin:bool -> ?stdin_once:bool -> ?env:string list -> ?workingdir:string -> ?networking:bool -> ?host:host_config -> ?name:string -> string -> string list -> id

create image cmd create a container and returns its ID where image is the image name to use for the container and cmd the command to run. cmd has the form [prog; arg1;...; argN]. BEWARE that the output of cmd (on stdout and stderr) will be logged by the container (see logs) so it will consume disk space.

  • parameter hostname

    the desired hostname to use for the container.

  • parameter domainname

    the desired domain name to use for the container.

  • parameter user

    the user (or UID) to use inside the container.

  • parameter stdin

    Attaches to stdin (default false).

  • parameter stdout

    Attaches to stdout (default true).

  • parameter stdout

    Attaches to stderr (default true).

  • parameter open_stdin

    opens stdin (sic).

  • parameter stdin_once

    Close stdin after the 1 attached client disconnects. Default: false.

  • parameter env

    A list of environment variables of the form "VAR=value". A variable without = is removed from the environment, rather than to have an empty value.

  • parameter workingdir

    The working dir for commands to run in.

  • parameter networking

    Whether networking is enabled for the container. Default: false.

  • parameter name

    The name of the container. The name must match /?[a-zA-Z0-9_-]+ or Invalid_argument is raised. It can be used in place of the container ID. If the name exists (whether the container is running or not), the container will not be recreated. Note that the corresponding name in t (as obtained by list) will have an initial '/' which means that the Docker daemon is the parent container.

val changes : ?addr:Unix.sockaddr -> id -> (string * [ `Modified | `Added | `Deleted ]) list

changes conn id returns which files in a container's filesystem have been added, deleted, or modified.

export conn id export the contents of container id.

val start : ?addr:Unix.sockaddr -> ?detach_keys:string -> id -> unit

start id starts the container id.

  • raises Server_error

    when, for example, if the command given by create does not exist in the container.

  • parameter detach_keys

    override the key sequence for detaching a container. Format is a single character [a-Z] or ctrl-<value> where <value> is one of: a-z, @, ^, [, , or _.

val stop : ?addr:Unix.sockaddr -> ?wait:int -> id -> unit

stop id stops the container id.

  • parameter wait

    number of seconds to wait before killing the container.

val wait : ?addr:Unix.sockaddr -> id -> int

wait id block until a container id stops, then returns the exit code.

val restart : ?addr:Unix.sockaddr -> ?wait:int -> id -> unit

restart id restart the container id.

  • parameter wait

    number of seconds to wait before killing the container.

val kill : ?addr:Unix.sockaddr -> ?signal:int -> id -> unit

kill id kill the container id.

  • parameter signal

    Signal to send to the container (see the standard module Sys). When not set, Sys.sigkill is assumed and the call will waits for the container to exit.

val pause : ?addr:Unix.sockaddr -> id -> unit

pause id pause the container id.

val unpause : ?addr:Unix.sockaddr -> id -> unit

unpause id unpause the container id.

val attach : ?addr:Unix.sockaddr -> ?stdin:bool -> ?stdout:bool -> ?stderr:bool -> id -> [ `Logs | `Stream | `Logs_and_stream ] -> Stream.t

attach id what view or interact with any running container id primary process (pid 1).

  • If what = `Logs replay the logs from the container: you will get the output since the container started.
  • If what = `Stream, stream stdin, stdout and stderr (if enabled) from the time the request was made onwards.
  • If what = `Logs_and_stream after getting the output of `Logs, it will seamlessly transition into streaming current output.
  • parameter stdin

    attach to stdin. Default false.

  • parameter stdout

    return and/or attach to stdout. Default false.

  • parameter stderr

    return and/or attach to stderr. Default false.

val rm : ?addr:Unix.sockaddr -> ?volumes:bool -> ?force:bool -> ?link:bool -> id -> unit

rm id remove the container id from the filesystem.

  • raises Docker.Invalid_argument

    if the container does not exist.

  • parameter volumes

    Remove the volumes associated to the container. Default false.

  • parameter force

    Kill then remove the container. Default false.

  • parameter link

    Remove the specified link associated with the container. Default: false.

module Exec : sig ... end