[Docker] wildfly Dockerfile을 이용한 Container 생성 (+Admin)
docker로 작업할 때 가장 효율이 나는 것들 중 하나는 바로 웹서버이다.
nginx 띄우는 예제는 많지만 wildfly를 더 많이 사용해왔기 때문에 wildfly container를 만들어 띄워보는 것을 해보겠다.
1. Host OS 방화벽 설정
#새로운 포트 개방
[minggu92@cloud dockerfiles]$ firewall-cmd --add-port=1003/tcp --permanent
SUCCESS!
[minggu92@cloud dockerfiles]$ firewall-cmd --reload
2. wildfly에서 제공하는 Dockerfile
# Use latest jboss/base-jdk:11 image as the base
FROM jboss/base-jdk:11
# Set the WILDFLY_VERSION env variable
ENV WILDFLY_VERSION 26.0.1.Final
ENV WILDFLY_SHA1 08908faf9ae99e5fb6374979afbffea461aadc2c
ENV JBOSS_HOME /opt/jboss/wildfly
USER root
# Add the WildFly distribution to /opt, and make wildfly the owner of the extracted tar content
# Make sure the distribution is available from a well-known place
RUN cd $HOME \
&& curl -L -O https://github.com/wildfly/wildfly/releases/download/$WILDFLY_VERSION/wildfly-$WILDFLY_VERSION.tar.gz \
&& sha1sum wildfly-$WILDFLY_VERSION.tar.gz | grep $WILDFLY_SHA1 \
&& tar xf wildfly-$WILDFLY_VERSION.tar.gz \
&& mv $HOME/wildfly-$WILDFLY_VERSION $JBOSS_HOME \
&& rm wildfly-$WILDFLY_VERSION.tar.gz \
&& chown -R jboss:0 ${JBOSS_HOME} \
&& chmod -R g+rw ${JBOSS_HOME}
# Ensure signals are forwarded to the JVM process correctly for graceful shutdown
ENV LAUNCH_JBOSS_IN_BACKGROUND true
USER jboss
# Expose the ports in which we're interested
EXPOSE 8080
# Set the default command to run on boot
# This will boot WildFly in standalone mode and bind to all interfaces
CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0"]
3. docker build
#docker build -t [name]:[tag] [경로] -f [*.Dockerfile]
[minggu92@cloud dockerfiles]$ docker build -t wildfly:0.1 /dockerfiles/ -f /dockerfiles/wildfly.Dockerfile
Sending build context to Docker daemon 5.12kB
Step 1/10 : FROM jboss/base-jdk:8
8: Pulling from jboss/base-jdk
75f829a71a1c: Pull complete
7b11f246b3d3: Pull complete
b765648c2a58: Pull complete
3672c49587a4: Pull complete
Digest: sha256:4ce172c6e0874a5e1b38a90dd6eda148f3e2fa1d196cba95e5a32dc0809286c8
Status: Downloaded newer image for jboss/base-jdk:8
---> b0802b3eccf0
Step 2/10 : ENV WILDFLY_VERSION 26.0.1.Final
---> Running in c239c89152d2
Removing intermediate container c239c89152d2
---> 1f170fb475fe
Step 3/10 : ENV WILDFLY_SHA1 08908faf9ae99e5fb6374979afbffea461aadc2c
---> Running in ad87a7569133
Removing intermediate container ad87a7569133
---> caebe17f0f49
Step 4/10 : ENV JBOSS_HOME /opt/jboss/wildfly
---> Running in 1c32c740d2f8
Removing intermediate container 1c32c740d2f8
---> 5e1338c9a63b
Step 5/10 : USER root
---> Running in cbb71484eb19
Removing intermediate container cbb71484eb19
---> ebe0bc90a9df
Step 6/10 : RUN cd $HOME && curl -L -O https://github.com/wildfly/wildfly/releases/download/$WILDFLY_VERSION/wildfly-$WILDFLY_VERSION.tar.gz && sha1sum wildfly-$WILDFLY_VERSION.tar.gz | grep $WILDFLY_SHA1 && tar xf wildfly-$WILDFLY_VERSION.tar.gz && mv $HOME/wildfly-$WILDFLY_VERSION $JBOSS_HOME && rm wildfly-$WILDFLY_VERSION.tar.gz && chown -R jboss:0 ${JBOSS_HOME} && chmod -R g+rw ${JBOSS_HOME}
---> Running in 8efc34f6999f
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 660 100 660 0 0 807 0 --:--:-- --:--:-- --:--:-- 808
100 207M 100 207M 0 0 368k 0 0:09:36 0:09:36 --:--:-- 1355k
08908faf9ae99e5fb6374979afbffea461aadc2c wildfly-26.0.1.Final.tar.gz
Removing intermediate container 8efc34f6999f
---> 700b6dc1974a
Step 7/10 : ENV LAUNCH_JBOSS_IN_BACKGROUND true
---> Running in 18d2acff9d47
Removing intermediate container 18d2acff9d47
---> 38b8214ce130
Step 8/10 : USER jboss
---> Running in 5306dfff81a9
Removing intermediate container 5306dfff81a9
---> e47f42fc981a
Step 9/10 : EXPOSE 8080
---> Running in caaa4e890999
Removing intermediate container caaa4e890999
---> f7ef1591a05c
Step 10/10 : CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0"]
---> Running in 0dccf31d8ec2
Removing intermediate container 0dccf31d8ec2
---> 6725a1d25a62
Successfully built 6725a1d25a62
Successfully tagged wildfly:0.1
4. docker run
#생성된 docker image 확인
[minggu92@cloud dockerfiles]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
wildfly 0.1 6725a1d25a62 13 minutes ago 757MB
jboss/base-jdk 8 b0802b3eccf0 18 months ago 495MB
#docker container 실행
[minggu92@cloud dockerfiles]$ docker run -p 1003:8080 wildfly:0.1
=========================================================================
JBoss Bootstrap Environment
JBOSS_HOME: /opt/jboss/wildfly
JAVA: /usr/lib/jvm/java/bin/java
JAVA_OPTS: -server -Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true
=========================================================================
04:45:12,433 INFO [org.jboss.modules] (main) JBoss Modules version 2.0.0.Final
04:45:13,419 INFO [org.jboss.msc] (main) JBoss MSC version 1.4.13.Final
04:45:13,445 INFO [org.jboss.threads] (main) JBoss Threads version 2.4.0.Final
....
....
8417ms - Started 298 of 538 services (337 services are lazy, passive or on-demand)
04:45:20,001 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
04:45:20,001 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
5. 확인
일단 서버가 기동 되는 것을 확인, 이제 상황에 맞게 커스터마이징 하면 된다.
6. Custormizing
# Use latest jboss/base-jdk:8 image as the base
FROM jboss/base-jdk:8
#metadata
LABEL name="minggu"
LABEL email="minha1002@gmail.com"
LABEL description="wildfly test"
FROM jboss/base-jdk:8
# Set the WILDFLY_VERSION env variable
ENV WILDFLY_VERSION 26.0.1.Final
ENV WILDFLY_SHA1 08908faf9ae99e5fb6374979afbffea461aadc2c
ENV JBOSS_HOME /opt/jboss/wildfly
USER root
# Add the WildFly distribution to /opt, and make wildfly the owner of the extracted tar content
# Make sure the distribution is available from a well-known place
RUN cd $HOME \
&& curl -L -O https://github.com/wildfly/wildfly/releases/download/$WILDFLY_VERSION/wildfly-$WILDFLY_VERSION.tar.gz \
&& sha1sum wildfly-$WILDFLY_VERSION.tar.gz | grep $WILDFLY_SHA1 \
&& tar xf wildfly-$WILDFLY_VERSION.tar.gz \
&& mv $HOME/wildfly-$WILDFLY_VERSION $JBOSS_HOME \
&& rm wildfly-$WILDFLY_VERSION.tar.gz \
&& chown -R jboss:0 ${JBOSS_HOME} \
&& chmod -R g+rw ${JBOSS_HOME}
# Install postgreSQL Driver
RUN mkdir -p ${JBOSS_HOME}/modules/system/layers/base/org/postgresql/main \
&& cd "$_" \
&& curl -sLO https://repo1.maven.org/maven2/org/postgresql/postgresql/42.3.3/postgresql-42.3.3.jar
# Change resources
ADD resources/module.xml ${JBOSS_HOME}/modules/system/layers/base/org/postgresql/main/module.xml
ADD resources/standalone.xml ${JBOSS_HOME}/standalone/configuration/standalone.xml
# Add war file
# volume ADD Crush
#ADD resources/skylark-vbn.war ${JBOSS_HOME}/standalone/deployments/
# Add wildfly admin account
USER jboss
#RUN bash -c "${JBOSS_HOME}/bin/add-user.sh admin minggu"
RUN /opt/jboss/wildfly/bin/add-user.sh -u admin -p minggu #admin --silent
# Make volume directory
# docker run -v is better than VOLUME
#VOLUME /opt/wildfly_docker/logs
#VOLUME ${JBOSS_HOME}/standalone/deployments
# Ensure signals are forwarded to the JVM process correctly for graceful shutdown
ENV LAUNCH_JBOSS_IN_BACKGROUND true
# Expose the ports in which we're interested
EXPOSE 8080 9990
# Set the default command to run on boot
# This will boot WildFly in standalone mode and bind to all interfaces
CMD /opt/jboss/wildfly/bin/standalone.sh -c standalone.xml -b 0.0.0.0 -bmanagement 0.0.0.0 --debug
#CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0"]
미리 module을 정의한 standalone.xml을 준비해서 실행하면 된다
팁! ADD 로 war 경로를 설정했지만 volume으로 선언하면 war가 add되지 않는다.
volume설정된 폴더로 war를 옮겨주자
Admin 페이지도 성공!
<참고>
https://github.com/jboss-dockerfiles/wildfly
https://colinch4.github.io/2020-12-03/README.docker/
'Server & Infra' 카테고리의 다른 글
[Jenkins] Docker로 Jenkins 빌드 및 설치 (0) | 2022.04.04 |
---|---|
[Docker] docker-compose 사용 (Compose V2) (0) | 2022.03.28 |
[Docker] Failed to get D-Bus connection: Operation not permitted (systemctl 명령어 사용실패) (0) | 2022.03.22 |
[Docker] Dockerfile생성, 그리고 build 하기 (ssh컨테이너용) (0) | 2022.03.22 |
[Docker] docker container commit, push (0) | 2022.03.21 |