Skip to content

Commit a17e455

Browse files
committed
docker
1 parent 9c16ea2 commit a17e455

File tree

4 files changed

+81
-7
lines changed

4 files changed

+81
-7
lines changed

docker/images/cmd-vs-entrypoint.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
Dockerfile:
2+
3+
FROM debian:wheezy
4+
ENTRYPOINT ["/bin/ping"]
5+
CMD ["localhost"]
6+
7+
Execution:
8+
Docker build -t test .
9+
Docker run -d test
10+
Docker run -it test google.com
11+
12+
13+
14+
15+
Dockerfile:
16+
FROM debian:wheezy
17+
CMD ["/bin/ping", "localhost"]
18+
19+
Execution:
20+
Docker build -t test2 .
21+
Docker run test2
22+
Docker run test2 bash
23+
24+
25+
The ENTRYPOINT specifies a command that will always be executed when the container starts. The CMD specifies arguments that will be fed to the ENTRYPOINT.
26+
27+
28+
29+
30+
Both CMD and ENTRYPOINT instructions define what command gets executed when running a container. There are few rules that describe their co-operation.
31+
1. Dockerfile should specify at least one of CMD or ENTRYPOINT commands.
32+
2. ENTRYPOINT should be defined when using the container as an executable.
33+
3. CMD should be used as a way of defining default arguments for an ENTRYPOINT command or for executing an ad-hoc command in a container.
34+
4. CMD will be overridden when running the container with alternative arguments
35+
36+
37+
38+
CMD
39+
╔════════════════════════════╦═════════════════════════════╗
40+
║ No CMD ║ error, not allowed ║
41+
╟────────────────────────────╫─────────────────────────────╢
42+
║ CMD [“exec_cmd”, “p1_cmd”] ║ exec_cmd p1_cmd ║
43+
╟────────────────────────────╫─────────────────────────────╢
44+
║ CMD [“p1_cmd”, “p2_cmd”] ║ p1_cmd p2_cmd ║
45+
╟────────────────────────────╫─────────────────────────────╢
46+
║ CMD exec_cmd p1_cmd ║ /bin/sh -c exec_cmd p1_cmd ║
47+
╚════════════════════════════╩═════════════════════════════╝
48+
49+
-- ENTRYPOINT exec_entry p1_entry
50+
╔════════════════════════════╦══════════════════════════════════╗
51+
║ No CMD ║ /bin/sh -c exec_entry p1_entry ║
52+
╟────────────────────────────╫──────────────────────────────────╢
53+
║ CMD [“exec_cmd”, “p1_cmd”] ║ /bin/sh -c exec_entry p1_entry ║
54+
╟────────────────────────────╫──────────────────────────────────╢
55+
║ CMD [“p1_cmd”, “p2_cmd”] ║ /bin/sh -c exec_entry p1_entry ║
56+
╟────────────────────────────╫──────────────────────────────────╢
57+
║ CMD exec_cmd p1_cmd ║ /bin/sh -c exec_entry p1_entry ║
58+
╚════════════════════════════╩══════════════════════════════════╝
59+
60+
-- ENTRYPOINT [“exec_entry”, “p1_entry”]
61+
╔════════════════════════════╦═════════════════════════════════════════════════╗
62+
║ No CMD ║ exec_entry p1_entry ║
63+
╟────────────────────────────╫─────────────────────────────────────────────────╢
64+
║ CMD [“exec_cmd”, “p1_cmd”] ║ exec_entry p1_entry exec_cmd p1_cmd ║
65+
╟────────────────────────────╫─────────────────────────────────────────────────╢
66+
║ CMD [“p1_cmd”, “p2_cmd”] ║ exec_entry p1_entry p1_cmd p2_cmd ║
67+
╟────────────────────────────╫─────────────────────────────────────────────────╢
68+
║ CMD exec_cmd p1_cmd ║ exec_entry p1_entry /bin/sh -c exec_cmd p1_cmd ║
69+
╚════════════════════════════╩═════════════════════════════════════════════════╝
70+
71+
72+

docker/images/dockerfile_myapp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ FROM ubuntu
22
RUN apt-get -y update
33
RUN apt-get -y install openjdk-8-jdk wget
44
RUN mkdir /opt/tomcat
5-
COPY tomcat-8.5.37.tar.gz /tmp
6-
RUN cd /tmp && tar xvfz tomcat-8.5.37.tar.gz
7-
RUN cp -Rv /tmp/apache-tomcat-8.5.37/* /opt/tomcat/
8-
RUN rm /tmp/tomcat-8.5.37.tar.gz
5+
# COPY tomcat-8.5.37.tar.gz /tmp
6+
# RUN cd /tmp && tar xvfz tomcat-8.5.37.tar.gz
7+
# RUN mv /tmp/apache-tomcat-8.5.37/* /opt/tomcat/
8+
# RUN rm /tmp/tomcat-8.5.37.tar.gz
9+
ADD tomcat-8.5.37.tar.gz /tmp
10+
RUN mv /tmp/apache-tomcat-8.5.37/* /opt/tomcat/
911
COPY myapp.war /opt/tomcat/webapps
1012
EXPOSE 8080
11-
CMD /opt/tomcat/bin/catalina.sh run
13+
ENTRYPOINT ["/opt/tomcat/bin/catalina.sh", "run"] ## JSON Format
14+
# ENTRYPOINT /opt/tomcat/bin/catalina.sh run ## Shell Format

docker/images/dockerfile_nginx2

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
FROM nginx
22
COPY index.html /var/www/html
3-
EXPOSE 80
4-
ENTRYPOINT /usr/sbin/nginx -g 'daemon off;'

kube/pods/pod.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ metadata:
44
name: tomcatpod
55
labels:
66
app: MyApp
7+
namespace: dev
78
spec:
89
containers:
910
- name: tomcat

0 commit comments

Comments
 (0)