cheatsheets/dockerfile.md

112 lines
1.7 KiB
Markdown
Raw Permalink Normal View History

2015-06-20 17:17:06 +00:00
---
title: Dockerfile
2015-11-24 05:02:17 +00:00
category: Devops
2018-03-19 07:40:58 +00:00
prism_languages: [docker]
2020-07-04 13:33:09 +00:00
updated: 2019-10-20
2015-06-20 17:17:06 +00:00
---
2017-08-29 21:52:27 +00:00
## Reference
{: .-three-column}
2015-06-20 17:17:06 +00:00
### Inheritance
2018-03-19 07:40:58 +00:00
```docker
2015-06-20 17:17:06 +00:00
FROM ruby:2.2.2
```
### Variables
2018-03-19 07:40:58 +00:00
```docker
2015-06-20 17:17:06 +00:00
ENV APP_HOME /myapp
RUN mkdir $APP_HOME
```
```docker
ARG APP_HOME=""
RUN mkdir $APP_HOME
```
2015-06-20 17:17:06 +00:00
### Initialization
2018-03-19 07:40:58 +00:00
```docker
2015-06-20 17:17:06 +00:00
RUN bundle install
```
2018-03-19 07:40:58 +00:00
```docker
2015-06-20 17:17:06 +00:00
WORKDIR /myapp
```
2016-06-18 16:19:06 +00:00
2018-03-19 07:40:58 +00:00
```docker
VOLUME ["/data"]
# Specification for mount point
```
```docker
ADD file.xyz /file.xyz
COPY --chown=user:group host_file.xyz /path/container_file.xyz
```
### Run commands in strict shell
```docker
ENV my_var
SHELL ["/bin/bash", "-euo", "pipefail", "-c"]
# With strict mode:
RUN false # fails build like using &&
RUN echo "$myvar" # will throw error due to typo
RUN true | false # will bail out of pipe
```
Using `shell` will turn on strict mode for shell commands.
2016-06-18 16:19:06 +00:00
### Onbuild
2018-05-14 04:43:30 +00:00
```docker
2017-08-29 21:52:27 +00:00
ONBUILD RUN bundle install
# when used with another file
2016-06-18 16:19:06 +00:00
```
### Commands
```docker
EXPOSE 5900
CMD ["bundle", "exec", "rails", "server"]
```
### Entrypoint
```docker
ENTRYPOINT ["executable", "param1", "param2"]
ENTRYPOINT command param1 param2
```
2018-03-17 05:30:02 +00:00
Configures a container that will run as an executable.
```docker
ENTRYPOINT exec top -b
```
2018-03-17 05:30:02 +00:00
This will use shell processing to substitute shell variables, and will ignore any `CMD` or `docker run` command line arguments.
### Metadata
2018-03-17 05:30:02 +00:00
```docker
LABEL version="1.0"
```
```docker
LABEL "com.example.vendor"="ACME Incorporated"
LABEL com.example.label-with-value="foo"
2018-03-19 07:40:58 +00:00
```
2018-03-17 05:30:02 +00:00
```docker
LABEL description="This text illustrates \
that label-values can span multiple lines."
```
2017-08-29 21:52:27 +00:00
## See also
{: .-one-column}
2016-06-18 16:19:06 +00:00
- <https://docs.docker.com/engine/reference/builder/>