The purpose of this document to collect the supported keywords with examples.
- from
- run
- cmd
- labels
- expose
- env
- add
- copy
- entrypoint
- volumes
- user
- working_dir
- args
- onbuild
- shell
- comment
"from": {
"type": "object",
"properties": {
"baseImage": {
"type": "string"
},
"alias": {
"type": "string"
}
},
"required": ["baseImage"]
}
For multi-stage build we are able to use multiple form statement. Please see the multi-stage example.
- baseImage: The name of the base image, what is the starting-point of this image.
- alias: The reference name of this build step. We are able to use the multi-stage builds.
{ "from": { "baseImage": "nginx:latest" } }
FROM nginx:latest
{ "from_1": { "baseImage": "nginx:latest", "alias": "http" } }
FROM nginx:latest AS http
"run" : {
"oneOf": [
{"type": "string"},
{"type": "array", "items": {"type": "string"}}
]
}
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)
{ "from": { "baseImage": "nginx:latest" }, "run": "test_runnable.sh" }
FROM nginx:latest
RUN [ "test_runnable.sh" ]
{ "from": { "baseImage": "nginx:latest" }, "run": ["test_runnable.sh", "param1", "param2"] }
FROM nginx:latest
RUN [ "test_runnable.sh", "param1", "param2" ]
"cmd" : {
"oneOf": [
{"type": "string"},
{"type": "array", "items": {"type": "string"}}
]
}
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)
{ "from": { "baseImage": "nginx:latest" }, "cmd": "test.cmd" }
FROM nginx:latest
CMD [ "test.cmd"]
{ "from": { "baseImage": "nginx:latest" }, "cmd": ["test.cmd", "-b"] }
FROM nginx:latest
CMD [ "test.cmd", "-b" ]
"labels": {
"oneOf": [
{
"type": "object",
"patternProperties": {
".+": {
"type": "string"
}
},
"additionalProperties": false
},
{"type": "array", "items": {"type": "string"}, "uniqueItems": true}
]
}
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.
const labels = {
key1: 'value1',
key2: 'value2',
};
{ "from": { "baseImage": "nginx:latest" }, "labels": labels }
FROM nginx:latest
LABEL key1=value1
LABEL key2=value2
const labels = [];
labels.key1 = 'value1';
labels.key2 = 'value2';
{ "from": { "baseImage": "nginx:latest" }, "labels": labels }
FROM nginx:latest
LABEL key1=value1
LABEL key2=value2
"expose": {
"type": "array",
"items": {
"type": ["string", "number"],
"format": "expose"
},
"uniqueItems": true
}
- A array which contains the list of exposed ports.
const expose = ['80', '22', '443'];
{ from: { baseImage: 'nginx:latest' }, "expose": expose}
FROM nginx:latest
EXPOSE 80
EXPOSE 22
EXPOSE 443
"env": {
"oneOf": [
{
"type": "object",
"patternProperties": {
".+": {
"type": ["string", "number", "null"]
}
},
"additionalProperties": false
},
{"type": "array", "items": {"type": "string"}, "uniqueItems": true}
]
}
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.
const env = {
key1: 'value1',
key2: 'value2',
};
{ "from": { "baseImage": "nginx:latest" }, "env": env }
FROM nginx:latest
ENV key1=value1
ENV key2=value2
const env = [];
env.key1 = 'value1';
env.key2 = 'value2';
{ "from": { "baseImage": "nginx:latest" }, "env": env }
FROM nginx:latest
ENV key1=value1
ENV key2=value2
"add": {
"oneOf": [
{"type": "array", "items": {"type": "string"}},
{"type": "object"}
]
}
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.
const add = {};
add.key1 = 'value1';
add.key2 = 'value2';
{ "from": { "baseImage": "nginx:latest" }, "add": add }
FROM nginx:latest
ADD key1 value1
ADD key2 value2
const add = [];
add.key1 = 'value1';
add.key2 = 'value2';
{ "from": { "baseImage": "nginx:latest" }, "add": add }
FROM nginx:latest
ADD key1 value1
ADD key2 value2
"copy": {
"oneOf": [
{"type": "array", "items": {"type": "string"}},
{"type": "object"}
]
}
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.
const copy = {};
copy.key1 = 'value1';
copy.key2 = 'value2';
{ "from": { "baseImage": "nginx:latest" }, "copy": copy }
FROM nginx:latest
COPY key1 value1
COPY key2 value2
const copy = [];
copy.key1 = 'value1';
copy.key2 = 'value2';
{ "from": { "baseImage": "nginx:latest" }, "copy": copy }
FROM nginx:latest
COPY key1 value1
COPY key2 value2
const copy = {};
copy.key1 = 'value1';
copy.key2 = 'value2';
copy.from = 0;
{ "from": { "baseImage": "nginx:latest" }, "copy": copy }
FROM nginx:latest
COPY --from=0 key1 value1
COPY --from=0 key2 value2
"entrypoint": {
"oneOf": [
{"type": "array", "items": {"type": "string"}},
{"type": "object"}
]
}
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.
{ "from": { "baseImage": "nginx:latest" }, "entrypoint": "test_runnable.sh" }
FROM nginx:latest
ENTRYPOINT [ "test_runnable.sh" ]
const entrypoint = ['test_runnable.sh', 'param1', 'param2'];
{ "from": { "baseImage": "nginx:latest" }, "entrypoint": entrypoint }
FROM nginx:latest
ENTRYPOINT [ "test_runnable.sh", "param1", "param2" ]
"volumes": {
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true
}
Volumes is array, which contains the path of the volumes.
const volumes = ['/home/app/1', '/home/app/2'];
{ "from": { "baseImage": "nginx:latest" }, "volumes": volumes }
FROM nginx:latest
VOLUME /home/app/1
VOLUME /home/app/2
"user": {
"type": "string"
}
- The name of the user, which is a string.
{ from: { baseImage: 'nginx:latest' }, user: 'username' }
FROM nginx:latest
USER username
"working_dir": {
"type": "string"
}
- The full path of the working directory.
{ from: { baseImage: 'nginx:latest' }, working_dir: '/home/app' }
FROM nginx:latest
WORKDIR /home/app
"args": {
"oneOf": [
{"type": "array", "items": {"type": "string"}, "uniqueItems": true}
]
}
ARGS is array, which contains the values of the required arguments.
{ "from": { "baseImage": "nginx:latest" }, "args": ['arg1', 'arg2'] }
FROM nginx:latest
ARG arg1
ARG arg2
"stopsignal": {
"type": "string"
}
- The full path of the working directory.
{ from: { baseImage: 'nginx:latest' }, stopsignal: 'signal' }
FROM nginx:latest
STOPSIGNAL signal
"shell": {
"type": "array", "items": {"type": "string"}, "uniqueItems": true
}
SHELL is array, which contains the executable and params of the shell command.
{ "from": { "baseImage": "nginx:latest" }, "shell": ['executable', 'arg1', 'arg2'] }
FROM nginx:latest
SHELL ["executable", "arg1", "arg2"]
"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.
COMMENT is a string.
{ "from": { "baseImage": "nginx:latest" }, "comment": "single comment" }
FROM nginx:latest
# single comment
{ "from": { "baseImage": "nginx:latest" }, "comment_1": "first comment","comment_2": "second comment" }
FROM nginx:latest
# first comment
# second comment