μ•ˆλ…•ν•˜μ„Έμš” μ΄μ •μš΄ μž…λ‹ˆλ‹€.

이번 κ°•μ’Œμ—λŠ” μš”μ¦˜μ— λŒ€μ„ΈμΈ Docker 에 λŒ€ν•΄μ„œ 곡뢀도 ν•΄λ³Όκ²Έ Open Liberty 에 λŒ€ν•œ Docker image λ₯Ό 가지고 μˆ˜ν–‰ 및 이리 저리 ν…ŒμŠ€νŠΈλ„ ν•΄λ³΄λŠ” ν˜•νƒœλ‘œ ν…ŒμŠ€νŠΈλ₯Ό κ°„λ‹¨ν•˜κ²Œ μˆ˜ν–‰ 해보도둝 ν•˜κ² μŠ΅λ‹ˆλ‹€.
(저도 docker λΆ€λΆ„μ—μ„œλŠ” μ „λ¬Έκ°€κ°€ μ•„λ‹ˆλΌμ„œ 이런 μ €λŸ° 자료 μ·¨ν•©ν•˜κ³  μ—¬λŸ¬λ²ˆ ν…ŒμŠ€νŠΈν•΄μ„œ μ œκ°€ μ΄ν•΄λœ 뢀뢄에 λŒ€ν•΄μ„œλ§Œ μ„€λͺ…(?)λ“œλ¦΄ 수 μžˆλ‹€λŠ” ν•œκ³„κ°€ μžˆλ‹€λŠ” 점은 μ–‘ν•΄ λΆ€νƒλ“œλ¦¬κ² μŠ΅λ‹ˆλ‹€.)

#1) Open Liberty 에 λŒ€ν•œ Docker image 확인 및 κ°„λ‹¨ν•œ ν…ŒμŠ€νŠΈ

ν•˜λ‹¨μ˜ docker hub λ₯Ό λ³΄μ‹œλ©΄ μ•„μ‹œκ² μ§€λ§Œ Open Liberty 에 λŒ€ν•œ 곡식 Docker image λ₯Ό μ œκ³΅ν•  뿐만 μ•„λ‹ˆλΌ μ§€μ›ν•˜λŠ” ν‘œμ€€μ— 따라 λ‹€μ–‘ν•œ tag λ₯Ό μ œκ³΅ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€.

https://hub.docker.com/r/openliberty/open-liberty/

github λ₯Ό ν†΅ν•΄μ„œ λ³΄μ‹œλ©΄ μ•„μ‹œκ² μ§€λ§Œ kernel, microProfile1, javaee7, webProfile7 μ΄λΌλŠ” 총 4가지 ν˜•νƒœμ˜ tag λ₯Ό μ œκ³΅ν•©λ‹ˆλ‹€. (https://github.com/OpenLiberty/ci.docker/tree/master/release)

μš°μ„  κ°€μž₯ 기본이 λ˜λŠ” kernel 둜 νƒœκ·Έλœ Dockerfile 을 μ‚΄νŽ΄λ³΄λ©΄ ν•˜λ‹¨κ³Ό κ°™μŠ΅λ‹ˆλ‹€. μ—¬κΈ°μ„œ Docker 에 λŒ€ν•΄μ„œ 깊게 닀루지 μ•Šμ„κ±°λΌ κΈ΄ μ„€λͺ…은 μ•ˆν•  κ±°μ§€λ§Œ 기본적으둜 “FROM ibmjava:8-jre” 보면 μ•„μ‹œκ² μ§€λ§Œ κ°€μž₯ 기본적으둜 μ‚¬μš©λ˜λŠ” Docker image λŠ” IBM Java 8.0 JRE κ΄€λ ¨ image μž…λ‹ˆλ‹€. μ–΄λ–»κ²Œ 보면 Linux ν™˜κ²½μ—μ„œ Tomcat λŒ€λΉ„ Open Liberty 의 κ°€μž₯ λ‹€λ₯Έ 점은 κΈ°λ³Έ JVM 으둜 IBM Java λ₯Ό μ‚¬μš©ν•  수 μžˆλ‹€λŠ” 점이며 이에 λ”°λ₯Έ μž₯점도 많이 가지고 μžˆμŠ΅λ‹ˆλ‹€. (μ’€ 더 μžμ„Έν•œ λ‚΄μš©μ€ 링크 μ°Έκ³  – http://www.websphere.pe.kr/xe/was_technotes/63497 )

즉, κΈ°λ³Έ IBM Java 8.0 JRE μ—μ„œ IBM repository 둜 μ ‘κ·Όν•˜μ—¬ Open Liberty λ₯Ό 직접 μ„€μΉ˜ν•˜λŠ” ν˜•νƒœλ‘œ κ΅¬μ„±λ˜μ–΄ 있으며 μ„œλΉ„μŠ€λ₯Ό μœ„ν•΄μ„œ HTTP(9080), HTTPS(9443) 포트λ₯Ό λ…ΈμΆœν•˜λ„λ‘ λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€.

——– Dockerfile for kernelΒ  ————————————————————————-
FROM ibmjava:8-jre
LABEL maintainer=”Alasdair Nottingham” vendor=”Open Liberty” url=”https://openliberty.io/”; github=”https://github.com/OpenLiberty/ci.docker”;
RUN apt-get update \
&& apt-get install -y –no-install-recommends unzip \
&& rm -rf /var/lib/apt/lists/*
# Install Open Liberty
ENV LIBERTY_VERSION 17.0.0.3
ENV LIBERTY_SHA 528e393e0b240ebbedb91d25402e22297c6d56ec
RUN wget https://repo1.maven.org/maven2/io/openliberty/openliberty-runtime/$LIBERTY_VERSION/openliberty-runtime-$LIBERTY_VERSION.zip -U UA-Open-Liberty-Docker -O /tmp/wlp.zip \
&& echo “$LIBERTY_SHAΒ  /tmp/wlp.zip” > /tmp/wlp.zip.sha1 \
&& sha1sum -c /tmp/wlp.zip.sha1 \
&& unzip -q /tmp/wlp.zip -d /opt/ol \
&& rm /tmp/wlp.zip \
&& rm /tmp/wlp.zip.sha1
ENV PATH=/opt/ol/wlp/bin:$PATH
# Set Path Shortcuts
ENV LOG_DIR=/logs \
WLP_OUTPUT_DIR=/opt/ol/wlp/output
RUN mkdir /logs \
&& ln -s $WLP_OUTPUT_DIR/defaultServer /output \
&& ln -s /opt/ol/wlp/usr/servers/defaultServer /config
# Configure WebSphere Liberty
RUN /opt/ol/wlp/bin/server create \
&& rm -rf $WLP_OUTPUT_DIR/.classCache /output/workarea
COPY docker-server /opt/ol/docker/
EXPOSE 9080 9443
CMD [“/opt/ol/docker/docker-server”, “run”, “defaultServer”] ——– Dockerfile for kernelΒ  ————————————————————————-

λ‹€μŒμœΌλ‘œ μ‹€μ œμ μœΌλ‘œ ν…ŒμŠ€νŠΈν•΄λ³Ό microProfile1 에 λŒ€ν•œ Dockerfile 은 kernel 을 κ·ΈλŒ€λ‘œ 상속 λ°›μœΌλ©΄μ„œ server.xml 만 μΆ”κ°€ λ©λ‹ˆλ‹€.

——– Dockerfile for microProfile ————————————————————————-
FROM openliberty/open-liberty:kernel
COPY server.xml /config/
——– Dockerfile for microProfile ————————————————————————-

server.xml 은 이전에도 κ°„λ‹¨νžˆ μ„€λͺ…λ“œλ Έμ§€λ§Œ Open Liberty 의 μ„€μ • 파일이며 μ‰½κ²Œ μ½κ±°λ‚˜ 이해할 수 있으며 Feature 뢀뢄을 λ³΄μ‹œλ©΄ μ•„μ‹œκ² μ§€λ§Œ microProfile-1.2 κΈ°λŠ₯을 μ‚¬μš©ν•œλ‹€λŠ” 것을 μ§κ΄€μ μœΌλ‘œ μ•Œ 수 μžˆμŠ΅λ‹ˆλ‹€. Open Liberty 의 κ°€μž₯ 큰 차별점은 Feature 에 JSP, Servlet, JAX-RS 와 같이 μ„ μ–Έν•˜μ—¬ κ·Έ κΈ°λŠ₯λ§Œμ„ λ°”λ‘œ μ‚¬μš©ν•  수 μžˆλ‹€λŠ” κ²ƒμž…λ‹ˆλ‹€.

https://github.com/OpenLiberty/ci.docker/blob/master/release/microProfile1/server.xml

——–server.xml————————————————————————-
<?xml version=”1.0″ encoding=”UTF-8″?>
<server description=”new server”>
<!– Enable features –>
<featureManager>
<feature>microProfile-1.2</feature>
</featureManager>
<!– To access this server from a remote client add a host attribute to the following element, e.g. host=”*” –>
<httpEndpoint id=”defaultHttpEndpoint”
httpPort=”9080″
httpsPort=”9443″ />

<!– Automatically expand WAR files and EAR files –>
<applicationManager autoExpand=”true”/>
</server>
——–server.xml————————————————————————-

μ—¬κΈ°μ„œ μ‚¬μš©ν•œ microProfile-1.2 λŠ” Java EE ν‘œμ€€μ„ 기반으둜 Microservice Architecture 에 μ ν•©ν•˜κ²Œ μ»€μŠ€ν„°λ§ˆμ΄μ§• ν•˜κ³  MSA 에 ν•„μš”ν•œ μƒˆλ‘œμš΄ ν‘œμ€€μ„ μΆ”κ°€ μ œκ³΅ν•˜λŠ” μ˜€ν”ˆμ†ŒμŠ€ μž…λ‹ˆλ‹€.Β  IBM, Redhat, Smartbear λ“± λ‹€μ–‘ν•œ 벀더가 μ°Έμ—¬ν•˜μ—¬ JAX-RS + CDI + JSON-P κ³Ό 같은 Java μ—”ν„°ν”„λΌμ΄μ¦ˆ ν‘œμ€€μ„ 기반으둜 λ§ˆμ΄ν¬λ‘œμ„œλΉ„μŠ€ μ•„ν‚€ν…μ²˜λ₯Ό μœ„ν•œ μ΅œμ ν™”λ₯Ό μˆ˜ν–‰ν•˜λŠ” 것을 κ·Έ λͺ©μ μœΌλ‘œ ν•˜λ©° ν•˜λ‹¨μ— λ³΄μ‹œλŠ” κ²ƒμ²˜λŸΌ Microservice Architecture ꡬ좕에 ν•„μˆ˜μ μΈ Fault Tolerance, Config, Healthcheck, Metric λ“± 좔가적인 ν‘œμ€€ν™” μž‘μ—…μ„ μˆ˜ν–‰ν•˜κ³  μžˆλŠ” Java EE ν‘œμ€€μ˜ μƒˆλ‘œμš΄ λ¬Όκ²°μž…λ‹ˆλ‹€. (보닀 μžμ„Έν•œ 사항은 http://microprofile.io μ—μ„œ μΆ”κ°€ 확인 κ°€λŠ₯ν•©λ‹ˆλ‹€. )

이제 docker hub μ—μ„œ 직접 Open liberty λ₯Ό μœ„ν•œ λ‹€μ–‘ν•œ Dockerfile 을 ν™•μΈν•΄λ΄€μœΌλ‹ˆ μ‹€μ œλ‘œ ν…ŒμŠ€νŠΈλ₯Ό μˆ˜ν–‰ν•΄ 보도둝 ν•˜κ² μŠ΅λ‹ˆλ‹€.

μš°μ„  제일 μ²˜μŒμœΌλ‘œλŠ” ν•˜λ‹¨κ³Ό 같이 docker hub μ—μ„œ μ‚¬μš©ν•  docker image λ₯Ό λ°›μ•„μ˜΅λ‹ˆλ‹€.

docker pull openliberty/open-liberty:microProfile1

μ΄λ ‡κ²Œ κ°€μ§€κ³ μ˜¨ docker image λ₯Ό ‘run’ λͺ…λ Ήμ–΄λ₯Ό ν†΅ν•΄μ„œ ν•˜λ‹¨κ³Ό 같이 μˆ˜ν–‰ν•˜λ©΄ docker container κ°€ μ‹€μ œ μˆ˜ν–‰λ©λ‹ˆλ‹€.
(μ—¬κΈ°μ„œ -p μ˜΅μ…˜μ€ 포트 바인딩을 ν•΄μ£ΌλŠ” μ˜΅μ…˜μœΌλ‘œ docker host 의 80 포트λ₯Ό μ‹€μ œ μˆ˜ν–‰ν•˜λŠ” docker container 의 9080 κ³Ό μ—°κ²°ν•΄μ£ΌλŠ” κ²ƒμž…λ‹ˆλ‹€.)

docker run -d -p 80:9080 -it --name openliberty openliberty/open-liberty:microProfile1

μœ„μ™€ 같이 μˆ˜ν–‰μ„ ν•˜κ²Œλ˜λ©΄ Docker Container κ°€ μˆ˜ν–‰λ˜λ©΄μ„œ μ›Ή λΈŒλΌμš°μ €λ₯Ό ν†΅ν•΄μ„œ 80 포트둜 Open Liberty 에 μ ‘κ·Ό κ°€λŠ₯ν•œ 것을 확인 κ°€λŠ₯ν•©λ‹ˆλ‹€.

μ΄λ ‡κ²Œ μ„œλΉ„μŠ€λœ docker container λŠ” ν•˜λ‹¨κ³Ό 같이 log λ₯Ό ν™•μΈν•˜κ±°λ‚˜ , top λͺ…령을 ν†΅ν•΄μ„œ process λ₯Ό ν™•μΈν•˜κ±°λ‚˜ μ‹€μ œ docker container μ•ˆμœΌλ‘œ 직접 λ“€μ–΄κ°€μ„œ file 을 μ œμ–΄ν•˜κ±°λ‚˜ 일반 OS 처럼 μ‘°μž‘ ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

docker logs --tail=all -f openliberty

docker top openliberty

docker exec -it openliberty bash

참고둜 ν•˜λ‹¨μ˜ λͺ…λ ΉμœΌλ‘œ docker container λ₯Ό 쀑지 ν•˜κ±°λ‚˜ μ‚­μ œκ°€ κ°€λŠ₯ν•©λ‹ˆλ‹€. (docker container 에 λŒ€ν•œ μ‚­μ œκ°€ μˆ˜ν–‰λ  뿐 μ‹€μ œ docker image λŠ” μ§€μ›Œμ§€μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. docker image λ₯Ό μ§€μš°κΈ° μœ„ν•΄μ„œλŠ” ‘docker rmi’ λͺ…λ Ήμ–΄λ₯Ό μˆ˜ν–‰ν•΄μ•Ό ν•©λ‹ˆλ‹€.)
sudo docker stop wlp
sudo docker rm wlp

#2) Open Liberty 에 λŒ€ν•œ κΈ°λ³Έ docker image λ₯Ό ν™•μž₯ν•˜κΈ°

κ°„λ‹¨ν•œ μƒ˜ν”Œ servlet μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ„ μ€€λΉ„ν•˜κ³  ν˜„μž¬ λ™μž‘ν•˜κ³  μžˆλŠ” docker container 의 /config/dropins 폴더에 λ³΅μ‚¬ν•©λ‹ˆλ‹€.
(Open Liberty λŠ” μ§€μ •λœ νŠΉμ • 폴더에 μ• ν”Œλ¦¬μΌ€μ΄μ…˜ war, ear 만 볡사해도 μžλ™μœΌλ‘œ μΈμ‹ν•˜κ³  ν™•μž₯ν•˜μ—¬ λ°”λ‘œ μ„œλΉ„μŠ€λ₯Ό μ œκ³΅ν•  수 μžˆμŠ΅λ‹ˆλ‹€.)

docker cp /tmp/sample.servlet-2.1.0.war openliberty:/config/dropins/sample.servlet-2.1.0.war

μ°Έκ³  : μƒ˜ν”Œ μ„œλΈ”λ¦Ώμ€ github 에 μžˆλŠ” μƒ˜ν”Œ μ„œλΈ”λ¦Ώ μ‚¬μš© :Β  https://jitpack.io/com/github/WASdev/sample.servlet/2.1.0/sample.servlet-2.1.0.war

λ˜ν•œ, μ™ΈλΆ€μ—μ„œ μš”μ²­μ„ λ°›κΈ° μœ„ν•˜μ—¬ 주석에 μ–ΈκΈ‰λœ κ²ƒμ²˜λŸΌ ‘host=”*”‘ 을 ν•˜λ‹¨κ³Ό 같이 μΆ”κ°€ν•œ server.xml 을 λ§Œλ“­λ‹ˆλ‹€.
——–server.xml————————————————————————-
<?xml version=”1.0″ encoding=”UTF-8″?>
<server description=”new server”>
<!– Enable features –>
<featureManager>
<feature>microProfile-1.2</feature>
</featureManager>
<!– To access this server from a remote client add a host attribute to the following element, e.g. host=”*” –>
<httpEndpoint id=”defaultHttpEndpoint”
host=”*”
httpPort=”9080″
httpsPort=”9443″ />

<!– Automatically expand WAR files and EAR files –>
<applicationManager autoExpand=”true”/>
</server>
——–server.xml————————————————————————-

μ΄λ ‡κ²Œ λ§Œλ“€μ–΄μ§„ 섀정도 docker container 에 λ³΅μ‚¬ν•΄μ€λ‹ˆλ‹€. (κΈ° μ–ΈκΈ‰λ“œλ¦° κ²ƒμ²˜λŸΌ Open Liberty λŠ” OSGi 기반으둜 동적인 νŠΉμ„±μ„ 가지고 μžˆμ–΄μ„œ λ³„λ„μ˜ μž¬μ‹œμž‘ 없이도 λ™μ μœΌλ‘œ λ°˜μ˜λ©λ‹ˆλ‹€.)

docker cp /tmp/server.xml openliberty:/config/server.xml

μ‹€μ œλ‘œ μ›ΉλΈŒλΌμš°μ €λ₯Ό ν†΅ν•΄μ„œ ν…ŒμŠ€νŠΈν•΄λ³΄λ©΄ λ°”λ‘œ κ²°κ³Όλ₯Ό ν™•μΈν•˜μ‹€ 수 μžˆμŠ΅λ‹ˆλ‹€. (dropins 방식을 μ‚¬μš©ν•˜μ‹  경우 μ ‘κ·Όν•  context root λŠ” 파일λͺ… μž…λ‹ˆλ‹€.)
http://192.168.225.156/sample.servlet-2.1.0/

이제 ‘docker commit’ λͺ…령을 μ΄μš©ν•˜μ—¬ war μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ΄ μΆ”κ°€λœ docker container λ₯Ό ν™•μž₯ν•œ 채 docker image 둜 λ§Œλ“­λ‹ˆλ‹€.

docker commit -a "jwlee98@gmail.com" -m "add sample.servlet-2.1.0.war" openliberty openliberty:microProfile2

μ΄λ ‡κ²Œ ‘docker commit’ 을 ν†΅ν•΄μ„œ ν™•μž₯ν•œ docker image λ₯Ό ν†΅ν•΄μ„œ docker container λ₯Ό μƒμ„±ν•˜λ©΄ war μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ΄ μΆ”κ°€λœ 채 λ°”λ‘œ μˆ˜ν–‰ 및 κ²°κ³Όλ₯Ό 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.

결ꡭ은 DevOps κ΄€μ μ—μ„œ docker ν™˜κ²½μ„ κ³ λ €ν•œλ‹€λ©΄ μ΄λ ‡κ²Œ Open Liberty 와 μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ„ docker image 둜 λ¬Άμ–΄μ„œ 배포 및 μˆ˜ν–‰ ν•  수 μžˆλ‹€λŠ” μ˜λ―Έμž…λ‹ˆλ‹€. λ‹Ήμ—°νžˆ docker image λ₯Ό ν†΅ν•œ 버전 관리도 κ°€λŠ₯ν•˜κ² μ£ ..

μ–΄λ–»κ²Œ 이해가 μ’€ λ˜μ‹œλ‚˜μš”? docker λ₯Ό 사전에 μ‚¬μš©ν•΄ λ³Έ λΆ„λ“€μ—κ²ŒλŠ” μ•„μ£Ό μ‰¬μš΄ 이야기 일것이며 이제 처음 μ‚¬μš©ν•˜κ±°λ‚˜ Open Liberty μ‚¬μš©μžλΌλ„ κ·Έλ ‡κ²Œ 였래 κ³ λ―Όν•˜μ§€ μ•Šμ•„λ„ 이해할 수 μžˆμ§€ μ•Šμ„κΉŒ ν•©λ‹ˆλ‹€.

μ—¬κΈ°κΉŒμ§€ 잘 λ”°λΌμ˜€μ…¨λ‹€λ©΄ κΈ°μ–ΈκΈ‰ν•œ κ²ƒμ²˜λŸΌ Open Liberty 에 λŒ€ν•œ docker image λ₯Ό ν†΅ν•΄μ„œ κ°„λ‹¨νžˆ μ‚¬μš© 및 μ„œλΉ„μŠ€ 해보셨을 뿐만 μ•„λ‹ˆλΌ ‘commit’ 을 ν†΅ν•œ docker image ν™•μž₯등도 κ°„λ‹¨νžˆ μ‚΄νŽ΄λ³΄μ•˜λ‹€κ³  μƒκ°λ©λ‹ˆλ‹€. 그럼 이번 κ°•μ’ŒλŠ” μ—¬κΈ°μ„œ 이만 휘리릭~~~

ν† λ‘  μ°Έκ°€

이메일은 κ³΅κ°œλ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. ν•„μˆ˜ μž…λ ₯창은 * 둜 ν‘œμ‹œλ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€