Module Dockerfile
Generate Dockerfile scripts for use with the Docker container manager
Core combinators and serializers
val sexp_of_t : t ‑> Sexplib.Sexp.tsexp_of_t tconverts a Dockerfile into a s-expression representation.
val t_of_sexp : Sexplib.Sexp.t ‑> tt_of_sexp sconverts thess-expression representation into at. The s-expression should have been generated usingsexp_of_t.
val empty : tAn empty set of instruction lines.
Dockerfile commands
val comment : ('a, unit, string, t) Pervasives.format4 ‑> 'aAdds a comment to the Dockerfile for documentation purposes
val from : ?alias:string ‑> ?tag:string ‑> string ‑> tThe
frominstruction sets the base image for subsequent instructions.- A valid Dockerfile must have
fromas its first instruction. The image can be any valid image. frommust be the first non-comment instruction in the Dockerfile.fromcan appear multiple times within a single Dockerfile in order to create multiple images. Multiple FROM commands will result in a multi-stage build, and the?fromargument to thecopyandaddfunctions can move artefacts across stages.
By default, the stages are not named, and you refer to them by their integer number, starting with 0 for the first
FROMinstruction. However, you can name your stages, by supplying an?aliasargument. The alias can be supplied to the?fromparameter tocopyoraddto refer to this particular stage by name.If no
tagis supplied,latestis assumed. If the used tag does not exist, an error will be returned.- A valid Dockerfile must have
val maintainer : ('a, unit, string, t) Pervasives.format4 ‑> 'amaintainersets the author field of the generated images.
val run : ('a, unit, string, t) Pervasives.format4 ‑> 'arun fmtwill execute any commands in a new layer on top of the current image and commit the results. The resulting committed image will be used for the next step in the Dockerfile. The string result of formattingargwill be passed as a/bin/sh -cinvocation.
val run_exec : string list ‑> trun_exec argswill execute any commands in a new layer on top of the current image and commit the results. The resulting committed image will be used for the next step in the Dockerfile. Theargsform makes it possible to avoid shell string munging, and to run commands using a base image that does not contain/bin/sh.
val cmd : ('a, unit, string, t) Pervasives.format4 ‑> 'acmd argsprovides defaults for an executing container. These defaults can include an executable, or they can omit the executable, in which case you must specify anentrypointas well. The string result of formattingargwill be passed as a/bin/sh -cinvocation.There can only be one
cmdin a Dockerfile. If you list more than one then only the lastcmdwill take effect.
val cmd_exec : string list ‑> tcmd_exec argsprovides defaults for an executing container. These defaults can include an executable, or they can omit the executable, in which case you must specify anentrypointas well. The first argument to theargslist must be the full path to the executable.There can only be one
cmdin a Dockerfile. If you list more than one then only the lastcmdwill take effect.
val expose_port : int ‑> texpose_portinforms Docker that the container will listen on the specified network port at runtime.
val expose_ports : int list ‑> texpose_portsinforms Docker that the container will listen on the specified network ports at runtime.
val env : (string * string) list ‑> tenvsets the list of environment variables supplied with the (<key>, <value>) tuple. This value will be passed to all futureruninstructions. This is functionally equivalent to prefixing a shell command with<key>=<value>.
val add : ?from:string ‑> src:string list ‑> dst:string ‑> unit ‑> tadd ?from ~src ~dst ()copies new files, directories or remote file URLs fromsrcand adds them to the filesystem of the container at thedstpath.Multiple
srcresource may be specified but if they are files or directories then they must be relative to the source directory that is being built (the context of the build).Each
srcmay contain wildcards and matching will be done using Go's filepath.Match rules.All new files and directories are created with a UID and GID of 0. In the case where
srcis a remote file URL, the destination will have permissions of 600. If the remote file being retrieved has an HTTP Last-Modified header, the timestamp from that header will be used to set the mtime on the destination file. Then, like any other file processed during an ADD, mtime will be included in the determination of whether or not the file has changed and the cache should be updated.The
?fromparameter allows artefacts to be retrieved from multiplecommands. It can either be an integer number (starting with 0 for the firstfromcommand, or a named stage (supplied via?aliasto thefromcommand).
val copy : ?from:string ‑> src:string list ‑> dst:string ‑> unit ‑> tcopy ?from ~src ~dst ()copies new files or directories fromsrcand adds them to the filesystem of the container at the pathdst. Seeaddfor more detailed documentation.
val user : ('a, unit, string, t) Pervasives.format4 ‑> 'auser fmtsets the user name or UID to use when running the image and for anyrun,cmd,entrypointcommands that follow it in the Dockerfile.
val workdir : ('a, unit, string, t) Pervasives.format4 ‑> 'aworkdir fmtsets the working directory for anyrun,cmdandentrypointinstructions that follow it in the Dockerfile.It can be used multiple times in the one Dockerfile. If a relative path is provided, it will be relative to the path of the previous
workdirinstruction.
val volume : ('a, unit, string, t) Pervasives.format4 ‑> 'avolume fmtwill create a mount point with the specified name and mark it as holding externally mounted volumes from native host or other containers. The value can be a JSON array or a plain string with multiple arguments that specify several mount points.
val volumes : string list ‑> tvolumes mountswill create mount points with the specified names inmountsand mark them as holding externally mounted volumes from native host or other containers.
val entrypoint : ('a, unit, string, t) Pervasives.format4 ‑> 'aentrypoint fmtallows you to configure a container that will run as an executable. Thefmtstring will be executed using a/bin/shsubshell.The shell form prevents any
cmdorruncommand line arguments from being used, but has the disadvantage that yourentrypointwill be started as a subcommand of/bin/sh -c, which does not pass signals. This means that the executable will not be the container's PID 1 - and will not receive Unix signals - so your executable will not receive a SIGTERM fromdocker stop <container>.To get around this limitation, use the
entrypoint_execcommand to directly execute an argument list without a subshell.
val entrypoint_exec : string list ‑> tentrypoint fmtallows you to configure a container that will run as an executable. You can use the exec form here to set fairly stable default commands and arguments and then use eithercmdorcmd_execto set additional defaults that are more likely to be changed by the user starting the Docker container.
val onbuild : t ‑> tonbuild tadds to the image a trigger instructiontto be executed at a later time, when the image is used as the base for another build. The trigger will be executed in the context of the downstream build, as if it had been inserted immediately after thefrominstruction in the downstream Dockerfile.Any build instruction can be registered as a trigger.
This is useful if you are building an image which will be used as a base to build other images, for example an application build environment or a daemon which may be customized with user-specific configuration.
val label : (string * string) list ‑> tlabel ladds metadata to an image via a list of key-value pairs. To include spaces within a label value, use quotes and backslashes as you would in command-line parsing. An image can have more than one label. To specify multiple labels, Docker recommends combining labels into a single label instruction where possible. Each label instruction produces a new layer which can result in an inefficient image if you use many labels.Labels are additive including
LABELs inFROMimages. If Docker encounters a label/key that already exists, the new value overrides any previous labels with identical keys.To view an image’s labels, use the
docker inspectcommand.