The concept of exposed commands derives from the use of exposed ports in Docker. Similar to a port being exposed for accessing a container's service, a command is made available to the user shell in order to perform some task. This API makes use of Docker's label system to identify commands. Labels can be added to images in a Dockerfile using the LABEL instruction. Also, labels can be added to containers when they are run and can thus be defined in a docker-compose.yml file. Labels in both images and containers are considered in this API.
Docker label keys used in this API are defined as follows:
Expose a single command in the image. The value of this label is the command exposed to the user interface. When executed, this will execute the Docker image default command.
FROM hello-world
LABEL exposed.command.single=hello
The above label instruction will expose a command with the name hello
which will run the docker image (with no arguments) resulting in a hello-world message.
Label keys starting with exposed.command.multiple.
are inspected and the part of the key after that portion is used as the command name. The value is used as the command run in the container.
~
LABEL exposed.command.multiple.cksum="/usr/bin/cksum"
LABEL exposed.command.multiple.md5sum="/usr/bin/md5sum"
An image with the above labels should make the cksum
and the md5sum
available, which should run the commands in the container as defined by the label value.
The value of this label should be a command that is run inside the image used to get a key-value list of exposed commands. The command needs to be run independently without any mountpoints or docker-compose related dependencies.
FROM alpine:3.8
COPY exposed.commands /usr/local/bin
LABEL exposed.command.multiplecommand="/usr/local/bin/exposed.commands"