build docker image
#make dockerfile
#build dockerfile
[root@k8s-master docker-tomcat-war]# ll
합계 20
-rw-r--r--. 1 root root 110 4월 7 08:46 Dockerfile
-rw-r--r--. 1 root root 681 4월 7 08:39 README.md
-rw-r--r--. 1 root root 96 4월 7 08:39 docker-compose.yml
-rw-r--r--. 1 root root 4606 4월 7 08:39 sample.war
[root@k8s-master docker-tomcat-war]# vi Dockerfile
FROM tomcat
MAINTAINER gnoti@gmail.com
ADD sample.war /usr/local/tomcat/webapps/
CMD ["catalina.sh", "run"]
#build dockerfile
[root@k8s-master docker-tomcat-war]# docker build -t gnoti_tomcat .
Sending build context to Docker daemon 64kB
Step 1/4 : FROM tomcat
latest: Pulling from library/tomcat
f15005b0235f: Pull complete
41ebfd3d2fd0: Pull complete
b998346ba308: Pull complete
f01ec562c947: Pull complete
74c11ae3efe8: Pull complete
3a7e595a3ef5: Pull complete
208407758d73: Pull complete
b5238120a381: Pull complete
1716556aae46: Pull complete
1336a11b2bd2: Pull complete
Digest: sha256:c0ba286d9903006423ff4e2818845f1cc4046aa829bbfbc9b96f887423cd9f47
Status: Downloaded newer image for tomcat:latest
---> e36064f7c6f0
Step 2/4 : MAINTAINER gnoti@gmail.com
---> Running in 942dfec63c5e
Removing intermediate container 942dfec63c5e
---> c5ae81e40f59
Step 3/4 : ADD sample.war /usr/local/tomcat/webapps/
---> 68ac1efba791
Step 4/4 : CMD ["catalina.sh", "run"]
---> Running in 0191df313b61
Removing intermediate container 0191df313b61
---> 69264587b4d8
Successfully built 69264587b4d8
Successfully tagged gnoti_tomcat:latest
[root@k8s-master docker-tomcat-war]#
#exec tomcat on docker
[root@k8s-master docker-tomcat-war]# docker run -d -i -t --name=gtomcat -p 8812:8080 gnoti_tomcat
64d7a73c58265eaf7fd2c385096e5652673cbda21fb35d093a2f25a023318905
[root@k8s-master docker-tomcat-war]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
gnoti_tomcat latest 69264587b4d8 2 minutes ago 528MB
tomcat latest e36064f7c6f0 5 days ago 528MB
k8s.gcr.io/kube-proxy v1.18.0 43940c34f24f 12 days ago 117MB
k8s.gcr.io/kube-controller-manager v1.18.0 d3e55153f52f 12 days ago 162MB
k8s.gcr.io/kube-apiserver v1.18.0 74060cea7f70 12 days ago 173MB
k8s.gcr.io/kube-scheduler v1.18.0 a31f78c7c8ce 12 days ago 95.3MB
quay.io/coreos/flannel v0.12.0-amd64 4e9f801d2217 3 weeks ago 52.8MB
k8s.gcr.io/pause 3.2 80d28bedfe5d 7 weeks ago 683kB
k8s.gcr.io/coredns 1.6.7 67da37a9a360 2 months ago 43.8MB
k8s.gcr.io/etcd 3.4.3-0 303ce5db0e90 5 months ago 288MB
[root@k8s-master docker-tomcat-war]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
64d7a73c5826 gnoti_tomcat "catalina.sh run" 11 seconds ago Up 10 seconds 0.0.0.0:8812->8080/tcp gtomcat
a1c4f5545bdd 67da37a9a360 "/coredns -conf /etc…" 2 days ago Up 2 days k8s_coredns_coredns-66bff467f8-glbj5_kube-system_e46de87a-2c35-4078-9428-ca1859c2dc1a_0
c6eb3465a519 k8s.gcr.io/pause:3.2 "/pause" 2 days ago Up 2 days k8s_POD_coredns-66bff467f8-glbj5_kube-system_e46de87a-2c35-4078-9428-ca1859c2dc1a_0
866f0f4c0408 67da37a9a360 "/coredns -conf /etc…" 2 days ago Up 2 days k8s_coredns_coredns-66bff467f8-s9zp2_kube-system_1a8ab80b-f071-4249-be01-8ab751e1dd7f_0
a91da664513c k8s.gcr.io/pause:3.2 "/pause" 2 days ago Up 2 days k8s_POD_coredns-66bff467f8-s9zp2_kube-system_1a8ab80b-f071-4249-be01-8ab751e1dd7f_0
1433b8be15e4 43940c34f24f "/usr/local/bin/kube…" 2 days ago Up 2 days k8s_kube-proxy_kube-proxy-wd7dj_kube-system_4d48caaa-b3fc-4d6b-a0ae-53d3609103df_0
685cd05d7787 k8s.gcr.io/pause:3.2 "/pause" 2 days ago Up 2 days k8s_POD_kube-proxy-wd7dj_kube-system_4d48caaa-b3fc-4d6b-a0ae-53d3609103df_0
3ca22f014ea8 74060cea7f70 "kube-apiserver --ad…" 2 days ago Up 2 days k8s_kube-apiserver_kube-apiserver-k8s-master_kube-system_0a3da68d85d96749758c18fe76d428df_0
3d95ca9e2470 303ce5db0e90 "etcd --advertise-cl…" 2 days ago Up 2 days k8s_etcd_etcd-k8s-master_kube-system_94ee592d56c24040e2f1c23be755f008_0
a3bbf2f7244f a31f78c7c8ce "kube-scheduler --au…" 2 days ago Up 2 days k8s_kube-scheduler_kube-scheduler-k8s-master_kube-system_5795d0c442cb997ff93c49feeb9f6386_0
7d754c790518 d3e55153f52f "kube-controller-man…" 2 days ago Up 2 days k8s_kube-controller-manager_kube-controller-manager-k8s-master_kube-system_16c0b106893c92aa29fe120498337172_0
cb0a26a1f8f9 k8s.gcr.io/pause:3.2 "/pause" 2 days ago Up 2 days k8s_POD_kube-apiserver-k8s-master_kube-system_0a3da68d85d96749758c18fe76d428df_0
2435a57f6fda k8s.gcr.io/pause:3.2 "/pause" 2 days ago Up 2 days k8s_POD_etcd-k8s-master_kube-system_94ee592d56c24040e2f1c23be755f008_0
a47c534ef8a2 k8s.gcr.io/pause:3.2 "/pause" 2 days ago Up 2 days k8s_POD_kube-scheduler-k8s-master_kube-system_5795d0c442cb997ff93c49feeb9f6386_0
d919de94a47b k8s.gcr.io/pause:3.2 "/pause" 2 days ago Up 2 days k8s_POD_kube-controller-manager-k8s-master_kube-system_16c0b106893c92aa29fe120498337172_0
[root@k8s-master docker-tomcat-war]#
#text tomcat
[root@k8s-master docker-tomcat-war]# docker exec -i -t gtomcat /bin/bash
root@64d7a73c5826:/usr/local/tomcat# ls /usr/local/tomcat/webapps/
sample sample.war
root@64d7a73c5826:/usr/local/tomcat# exit
exit
[root@k8s-master docker-tomcat-war]# curl http://192.168.0.162:8812/sample/
<html>
<head>
<title>Sample "Hello, World" Application</title>
</head>
<body bgcolor=white>
<table border="0">
<tr>
<td>
<img src="images/tomcat.gif">
</td>
<td>
<h1>Sample "Hello, World" Application</h1>
<p>This is the home page for a sample application used to illustrate the
source directory organization of a web application utilizing the principles
outlined in the Application Developer's Guide.
</td>
</tr>
</table>
<p>To prove that they work, you can execute either of the following links:
<ul>
<li>To a <a href="hello.jsp">JSP page</a>.
<li>To a <a href="hello">servlet</a>.
</ul>
</body>
</html>
[root@k8s-master docker-tomcat-war]#
댓글
댓글 쓰기