Env
Format:$variable_name、${variable_name}
- ${variable:-word} indicates that if variable is set then the result will be that value. If variable is not set then word will be the result.
- ${variable:+word} indicates that if variable is set then word will be the result, otherwise the result is the empty string.
Usage
1 | ENV abc=hello |
1 | FROM busybox |
1 | CMD ["sh", "-c", "django-admin startproject $PROJECTNAME"] |
Example
- Java Use Environment Parameter
需要注意点:
- CMD[“java”, “$environment”, “-jar”, “jar_path”],其中的环境变量是无法解析的。
- CMD [“sh”, “-c”, “echo $environment”],可以解析环境变量,是因为调用sh进行执行。
1 | # 基础镜像 |
1 | # entrypoint.sh |
1 | # execute.sh |
ARG
The ARG instruction defines a variable that users can pass at build-time to the builder with the docker build command using the –build-arg
If a user specifies a build argument that was not defined in the Dockerfile, the build outputs a warning.
Usage
1 | docker build --build-arg user=what_user . |
Add/Copy
[The Difference between COPY and ADD in a Dockerfile] https://nickjanetakis.com/blog/docker-tip-2-the-difference-between-copy-and-add-in-a-dockerile