OSDN Git Service

Regular updates
[twpd/master.git] / dockerfile.md
1 ---
2 title: Dockerfile
3 category: Devops
4 layout: 2017/sheet
5 prism_languages: [docker]
6 updated: 2019-10-20
7 ---
8
9 ## Reference
10 {: .-three-column}
11
12 ### Inheritance
13
14 ```docker
15 FROM ruby:2.2.2
16 ```
17
18 ### Variables
19
20 ```docker
21 ENV APP_HOME /myapp
22 RUN mkdir $APP_HOME
23 ```
24
25 ```docker
26 ARG APP_HOME=""
27 RUN mkdir $APP_HOME
28 ```
29
30 ### Initialization
31
32 ```docker
33 RUN bundle install
34 ```
35
36 ```docker
37 WORKDIR /myapp
38 ```
39
40 ```docker
41 VOLUME ["/data"]
42 # Specification for mount point
43 ```
44
45 ```docker
46 ADD file.xyz /file.xyz
47 COPY --chown=user:group host_file.xyz /path/container_file.xyz
48 ```
49
50 ### Run commands in strict shell
51
52 ```docker
53 ENV my_var
54 SHELL ["/bin/bash", "-euo", "pipefail", "-c"]
55
56 # With strict mode:
57 RUN false # fails build like using &&
58 RUN echo "$myvar" # will throw error due to typo
59 RUN true | false # will bail out of pipe
60 ```
61
62 Using `shell` will turn on strict mode for shell commands.
63
64 ### Onbuild
65
66 ```docker
67 ONBUILD RUN bundle install
68 # when used with another file
69 ```
70
71 ### Commands
72
73 ```docker
74 EXPOSE 5900
75 CMD    ["bundle", "exec", "rails", "server"]
76 ```
77
78 ### Entrypoint
79
80 ```docker
81 ENTRYPOINT ["executable", "param1", "param2"]
82 ENTRYPOINT command param1 param2
83 ```
84
85 Configures a container that will run as an executable.
86
87 ```docker
88 ENTRYPOINT exec top -b
89 ```
90
91 This will use shell processing to substitute shell variables, and will ignore any `CMD` or `docker run` command line arguments.
92
93 ### Metadata
94
95 ```docker
96 LABEL version="1.0"
97 ```
98
99 ```docker
100 LABEL "com.example.vendor"="ACME Incorporated"
101 LABEL com.example.label-with-value="foo"
102 ```
103
104 ```docker
105 LABEL description="This text illustrates \
106 that label-values can span multiple lines."
107 ```
108
109 ## See also
110 {: .-one-column}
111
112 - <https://docs.docker.com/engine/reference/builder/>