Skip to content

Latest commit

 

History

History
665 lines (570 loc) · 12.4 KB

References.md

File metadata and controls

665 lines (570 loc) · 12.4 KB

Dockerfile-generator reference

The purpose of this document to collect the supported keywords with examples.

Supported keywords

Keyword descriptions and examples

FROM

Keyword schema

"from": {
    "type": "object",
    "properties": {
        "baseImage": {
            "type": "string"
        },
        "alias": {
            "type": "string"
        }
    },
    "required": ["baseImage"]
}

Properties

For multi-stage build we are able to use multiple form statement. Please see the multi-stage example.

Required properties
  • baseImage: The name of the base image, what is the starting-point of this image.
Optional properties
  • alias: The reference name of this build step. We are able to use the multi-stage builds.

Example usages

Simple usage
Input
{ "from": { "baseImage": "nginx:latest" } }
Output
FROM nginx:latest
Multi-stage usage
Input
{ "from_1": { "baseImage": "nginx:latest", "alias": "http" } }
Output
FROM nginx:latest AS http

RUN

Keyword schema

"run" : {
    "oneOf": [
        {"type": "string"},
        {"type": "array", "items": {"type": "string"}}
    ]
}

Properties

Required properties

RUN has two forms

  • with one command: In this case the command is a runnable shell command. (Shell form)
  • with array, which contains a executable and the params of the executable. (Exec form)

Example usages

Shell form
Input
{ "from": { "baseImage": "nginx:latest" }, "run": "test_runnable.sh" }
Output
FROM nginx:latest
RUN [ "test_runnable.sh" ]
Exec form
Input
{ "from": { "baseImage": "nginx:latest" }, "run": ["test_runnable.sh", "param1", "param2"] }
Output
FROM nginx:latest
RUN [ "test_runnable.sh", "param1", "param2" ]

CMD

Keyword schema

"cmd" : {
    "oneOf": [
        {"type": "string"},
        {"type": "array", "items": {"type": "string"}}
    ]
}

Properties

Required properties

CMD has two forms

  • with one command: In this case the command is a runnable shell command. (Shell form)
  • with array, which contains a executable and the params of the executable. (Exec form)

Example usages

Shell form
Input
{ "from": { "baseImage": "nginx:latest" }, "cmd": "test.cmd" }
Output
FROM nginx:latest
CMD [ "test.cmd"]
Exec form
Input
{ "from": { "baseImage": "nginx:latest" }, "cmd": ["test.cmd", "-b"] }
Output
FROM nginx:latest
CMD [ "test.cmd", "-b" ]

LABELS

Keyword schema

"labels": {
    "oneOf": [
        {
            "type": "object",
            "patternProperties": {
                ".+": {
                    "type": "string"
                }
            },
            "additionalProperties": false
        },
        {"type": "array", "items": {"type": "string"}, "uniqueItems": true}
    ]
}

Properties

Required properties

Labels has two forms

  • Object: In this case the labels keyword is plain javascript object. The name of the label is the name of the attribute.
  • Array: In this case the labels keyword is array. The name of the label is the key of the element inside the array.

Example usages

Object form
Input
const labels = {
      key1: 'value1',
      key2: 'value2',
};

{ "from": { "baseImage": "nginx:latest" }, "labels": labels }
Output
FROM nginx:latest
LABEL key1=value1
LABEL key2=value2
Array form
Input
const labels = [];
labels.key1 = 'value1';
labels.key2 = 'value2';

{ "from": { "baseImage": "nginx:latest" }, "labels": labels }
Output
FROM nginx:latest
LABEL key1=value1
LABEL key2=value2

EXPOSE

Keyword schema

"expose": {
    "type": "array",
    "items": {
        "type": ["string", "number"],
        "format": "expose"
    },
    "uniqueItems": true
}

Properties

Required properties
  • A array which contains the list of exposed ports.

Example usages

Input
const expose = ['80', '22', '443'];

{ from: { baseImage: 'nginx:latest' }, "expose": expose}
Output
FROM nginx:latest
EXPOSE 80
EXPOSE 22
EXPOSE 443

ENV

Keyword schema

"env": {
    "oneOf": [
        {
            "type": "object",
            "patternProperties": {
                ".+": {
                    "type": ["string", "number", "null"]
                }
            },
            "additionalProperties": false
        },
        {"type": "array", "items": {"type": "string"}, "uniqueItems": true}
    ]
}

Properties

Required properties

ENV has two forms

  • Object: In this case the ENV keyword is plain javascript object. The name of the variable is the name of the attribute.
  • Array: In this case the ENV keyword is array. The name of variable is the key of the element inside the array.

Example usages

Object form
Input
 const env = {
    key1: 'value1',
    key2: 'value2',
};

{ "from": { "baseImage": "nginx:latest" }, "env": env }
Output
FROM nginx:latest
ENV key1=value1
ENV key2=value2
Array form
Input
const env = [];
env.key1 = 'value1';
env.key2 = 'value2';

{ "from": { "baseImage": "nginx:latest" }, "env": env }
Output
FROM nginx:latest
ENV key1=value1
ENV key2=value2

ADD

Keyword schema

"add": { 
    "oneOf": [
        {"type": "array", "items": {"type": "string"}},
        {"type": "object"}
    ]
}

Properties

Required properties

ADD has two forms

  • Object: In this case the ADD keyword is plain javascript object. The source of the added file is the name of the attribute. The destination is the value of the attribute.
  • Array: In this case the ADD keyword is array. The source of the added file is the key of the item. The destination is the value of the item.

Example usages

Object form
Input
const add = {};
add.key1 = 'value1';
add.key2 = 'value2';

{ "from": { "baseImage": "nginx:latest" }, "add": add }
Output
FROM nginx:latest
ADD key1 value1
ADD key2 value2
Array form
Input
const add = [];
add.key1 = 'value1';
add.key2 = 'value2';

{ "from": { "baseImage": "nginx:latest" }, "add": add }
Output
FROM nginx:latest
ADD key1 value1
ADD key2 value2

COPY

Keyword schema

"copy": { 
    "oneOf": [
        {"type": "array", "items": {"type": "string"}},
        {"type": "object"}
    ]
}

Properties

Required properties

COPY has two forms

  • Object: In this case the COPY keyword is plain javascript object. The source of the copied file is the name of the attribute. The destination is the value of the attribute.
  • Array: In this case COPY keyword is array. The source of the copied file is the key of the item. The destination is the value of the item.

For multi-stage builds we can use a --from switch with a copy keyword. Please see the multi-stage example below.

Example usages

Object form
Input
const copy = {};
copy.key1 = 'value1';
copy.key2 = 'value2';

{ "from": { "baseImage": "nginx:latest" }, "copy": copy }
Output
FROM nginx:latest
COPY key1 value1
COPY key2 value2
Array form
Input
const copy = [];
copy.key1 = 'value1';
copy.key2 = 'value2';

{ "from": { "baseImage": "nginx:latest" }, "copy": copy }
Output
FROM nginx:latest
COPY key1 value1
COPY key2 value2
Multi-stage
Input
const copy = {};
copy.key1 = 'value1';
copy.key2 = 'value2';
copy.from = 0;

{ "from": { "baseImage": "nginx:latest" }, "copy": copy }
Output
FROM nginx:latest
COPY --from=0 key1 value1
COPY --from=0 key2 value2

ENTRYPOINT

Keyword schema

"entrypoint": { 
    "oneOf": [
        {"type": "array", "items": {"type": "string"}},
        {"type": "object"}
    ]
}

Properties

Required properties

ENTRYPOINT has two forms

  • Object: In this case the ENTRYPOINT is a single string. This string is a name of a executable shell script.
  • Array: In this case COPY ENTRYPOINT is array. This array contains a executable shell script with parameters of the script.

Example usages

Object form
Input
{ "from": { "baseImage": "nginx:latest" }, "entrypoint": "test_runnable.sh" }
Output
FROM nginx:latest
ENTRYPOINT [ "test_runnable.sh" ]
Array form
Input
const entrypoint = ['test_runnable.sh', 'param1', 'param2'];

{ "from": { "baseImage": "nginx:latest" }, "entrypoint": entrypoint }
Output
FROM nginx:latest
ENTRYPOINT [ "test_runnable.sh", "param1", "param2" ]

VOLUMES

Keyword schema

"volumes": {
    "type": "array", 
    "items": {
        "type": "string"
    }, 
    "uniqueItems": true
}

Properties

Required properties

Volumes is array, which contains the path of the volumes.

Example usages

Input
const volumes = ['/home/app/1', '/home/app/2'];

{ "from": { "baseImage": "nginx:latest" }, "volumes": volumes }
Output
FROM nginx:latest
VOLUME /home/app/1
VOLUME /home/app/2

USER

Keyword schema

"user": {
    "type": "string"
}

Properties

Required properties
  • The name of the user, which is a string.

Example usages

Input
{ from: { baseImage: 'nginx:latest' }, user: 'username' }
Output
FROM nginx:latest
USER username

WORKING_DIR

Keyword schema

"working_dir": {
    "type": "string"
}

Properties

Required properties
  • The full path of the working directory.

Example usages

Input
{ from: { baseImage: 'nginx:latest' }, working_dir: '/home/app' }
Output
FROM nginx:latest
WORKDIR /home/app

ARGS

Keyword schema

"args": {
    "oneOf": [
        {"type": "array", "items": {"type": "string"}, "uniqueItems": true}
    ]
}

Properties

Required properties

ARGS is array, which contains the values of the required arguments.

Example usages

Input
{ "from": { "baseImage": "nginx:latest" }, "args": ['arg1', 'arg2'] }
Output
FROM nginx:latest
ARG arg1
ARG arg2

STOPSIGNAL

Keyword schema

"stopsignal": {
    "type": "string"
}

Properties

Required properties
  • The full path of the working directory.

Example usages

Input
{ from: { baseImage: 'nginx:latest' }, stopsignal: 'signal' }
Output
FROM nginx:latest
STOPSIGNAL signal

SHELL

Keyword schema

"shell": {
    "type": "array", "items": {"type": "string"}, "uniqueItems": true
}

Properties

Required properties

SHELL is array, which contains the executable and params of the shell command.

Example usages

Input
{ "from": { "baseImage": "nginx:latest" }, "shell": ['executable', 'arg1', 'arg2'] }
Output
FROM nginx:latest
SHELL ["executable", "arg1", "arg2"]

COMMENT

Keyword schema

"comment" : {
    "type": "string"
}

We are able to user multiple comment, for this we have to use the comment keyword with a suffix. Please see the example below.

Properties

Required properties

COMMENT is a string.

Example usages

Single comment
Input
{ "from": { "baseImage": "nginx:latest" }, "comment": "single comment" }
Output
FROM nginx:latest
# single comment
Multiple comment
Input
{ "from": { "baseImage": "nginx:latest" }, "comment_1": "first comment","comment_2": "second comment" }
Output
FROM nginx:latest
# first comment
# second comment