-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-file-directives
More file actions
128 lines (87 loc) · 3.35 KB
/
docker-file-directives
File metadata and controls
128 lines (87 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
=====================================================
Instructions :
=====================================================
Dockerfile syntax consists of two kind of main line blocks: comments and commands + arguments.
ex:-
# Print "Hello docker!"
RUN echo "Hello docker!"
Directives of Dockerfile:
-------------------------
FROM :
------
It defines the base image to use to start the build process.
ex:-
# Usage: FROM [image name]
FROM ubuntu
COPY :
------
adds files from your Docker client’s current directory.
ex:- COPY ./sample.txt /app/sample.txt
ADD :
-----
It basically copies the files from the source on the host into the container’s own filesystem at the set destination.
ex:-
# Usage: ADD [source directory or URL] [destination directory]
ADD /my_app_folder /my_app_folder
WORKDIR :
---------
The WORKDIR directive is used to set where the command defined with CMD is to be executed.
ex:-
# Usage: WORKDIR /path
WORKDIR ~/
RUN :
----
The RUN command is the central executing directive for Dockerfiles. It takes a command as its argument and runs it to form the image.
Unlike CMD, it actually is used to build the image (forming another layer on top of the previous one which is committed).
ex:-
# Usage: RUN [command]
RUN aptitude install -y riak
USER :
------
The USER directive is used to set the UID (or username) which is to run the container based on the image being built.
ex:-
# Usage: USER [UID]
USER 751
CMD :
-----
The command CMD, similarly to RUN, can be used for executing a specific command. However, unlike RUN it is not executed during build, but when a container is instantiated using the image being built.
Therefore, it should be considered as an initial, default command that gets executed (i.e. run) with the creation of containers based on the image.
ex:-
# Usage 1: CMD application "argument", "argument", ..
CMD "echo" "Hello docker!"
ENTRYPOINT :
------------
ENTRYPOINT instruction is used to set executables that will always run when the container is initiated. Unlike CMD commands, ENTRYPOINT commands cannot be ignored or overridden—even
when the container runs with command line arguments stated.
ex:-
# Usage: ENTRYPOINT application "argument", "argument", ..
# Remember: arguments are optional. They can be provided by CMD
# or during the creation of a container.
ENTRYPOINT echo
ENV :
-----
The ENV command is used to set the environment variables (one or more). These variables consist of “key value” pairs which can be accessed within the container by scripts and applications alike.
ex:-
# Usage: ENV key value
ENV SERVER_WORKS 4
LABEL :
-------
EXPOSE :
--------
The EXPOSE command is used to associate a specified port to enable networking between the running process inside the container and the outside world (i.e. the host).
ex:-
# Usage: EXPOSE [port]
EXPOSE 8080
MAINTAINER :
------------
One of the commands that can be set anywhere in the file - although it would be better if it was declared on top - is MAINTAINER.
This non-executing command declares the author, hence setting the author field of the images. It should come nonetheless after FROM.
ex:-
# Usage: MAINTAINER [name]
MAINTAINER authors_name
VOLUME :
--------
The VOLUME command is used to enable access from your container to a directory on the host machine (i.e. mounting it).
ex:-
# Usage: VOLUME ["/dir_1", "/dir_2" ..]
VOLUME ["/my_files"]