LoginSignup
3
0

More than 3 years have passed since last update.

Alpine LinuxベースでWebSphere Libertyイメージを作成してみる

Last updated at Posted at 2019-05-14

websphere-liberty:kernelのDockerイメージはibmjava:8-jreのイメージをベースとしていて、ibmjava:8-jreのイメージはubuntu:16.04をベースとしている。ibmjava:8-jre-alpineというalpine:3.7をベースとしたイメージがあるので、これを使ってLibertyイメージを作ってみたメモ。

作ってみたというだけで、サポートはされないと思われる。

Dockerfile

websphere-liberty:19.0.0.4-kernelのDockerfileの先頭のFROM ibmjava:8-jreを、FROM ibmjava:8-jre-alpineに書き換える。

その他以下の修正が必要。

  • Apline Linuxのではパッケージのインストールはapt-getではなくapkを使う必要があるが、opensslunzipはインストール済みなので記載を削除する
  • useraddがないので代わりにadduserを使う
  • ローカルからファイルをCOPYしているところがあるので、websphere-liberty:19.0.0.4-kernelのイメージからファイルをコピーするように変える
  • ENTRYPOINTを空にする
    • bashがないためENTRYPOINTに指定されている/opt/ibm/helpers/runtime/docker-server.shが動かない
    • このスクリプトはLICENSEKEYSTORE_REQUIREDという環境変数をみてちょっとした処理をしてからexecCMDに設定されたプロセスを起動して自分は終了しているだけなので、今回は使わないことにする
# (C) Copyright IBM Corporation 2019.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

-FROM ibmjava:8-jre
+FROM ibmjava:8-jre-alpine

LABEL maintainer="Arthur De Magalhaes <arthurdm@ca.ibm.com> (@arthurdm)"

# Install WebSphere Liberty
ENV LIBERTY_VERSION 19.0.0_04

ARG LIBERTY_URL 
ARG DOWNLOAD_OPTIONS=""

-RUN apt-get update \
-    && apt-get install -y --no-install-recommends unzip openssl \
-    && rm -rf /var/lib/apt/lists/* \
-    && mkdir /licenses/ \
+RUN mkdir /licenses/ \
-    && useradd -u 1001 -r -g 0 -s /usr/sbin/nologin default \
+    && adduser -u 1001 -S -G root -s /sbin/nologin default \
    && LIBERTY_URL=${LIBERTY_URL:-$(wget -q -O - https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/downloads/wlp/index.yml  | grep $LIBERTY_VERSION -A 6 | sed -n 's/\s*kernel:\s//p' | tr -d '\r' )}  \
    && wget $DOWNLOAD_OPTIONS $LIBERTY_URL -U UA-IBM-WebSphere-Liberty-Docker -O /tmp/wlp.zip \
    && unzip -q /tmp/wlp.zip -d /opt/ibm \
    && rm /tmp/wlp.zip \
    && chown -R 1001:0 /opt/ibm/wlp \
-    && chmod -R g+rw /opt/ibm/wlp \
-    && apt-get purge --auto-remove -y unzip \
-    && apt-get purge --auto-remove -y wget \
-    && rm -rf /var/lib/apt/lists/*
+    && chmod -R g+rw /opt/ibm/wlp

ENV PATH=/opt/ibm/wlp/bin:/opt/ibm/helpers/build:$PATH

# Add labels for consumption by IBM Product Insights
LABEL "ProductID"="fbf6a96d49214c0abc6a3bc5da6e48cd" \
      "ProductName"="WebSphere Application Server Liberty" \
      "ProductVersion"="19.0.0.4" \
      "BuildLabel"="cl190420190419-0642"

# Set Path Shortcuts
ENV LOG_DIR=/logs \
    WLP_OUTPUT_DIR=/opt/ibm/wlp/output 

# Configure WebSphere Liberty
RUN /opt/ibm/wlp/bin/server create \
    && rm -rf $WLP_OUTPUT_DIR/.classCache /output/workarea

-COPY helpers/ /opt/ibm/helpers/
-COPY fixes/ /opt/ibm/fixes/
-COPY licenses/ /licenses/
+COPY --from=websphere-liberty:19.0.0.4-kernel /opt/ibm/helpers/ /opt/ibm/helpers/
+COPY --from=websphere-liberty:19.0.0.4-kernel /opt/ibm/fixes/ /opt/ibm/fixes/
+COPY --from=websphere-liberty:19.0.0.4-kernel /licenses/ /licenses/

# Create symlinks && set permissions for non-root user
RUN mkdir /logs \
    && mkdir /etc/wlp \
    && mkdir -p /opt/ibm/wlp/usr/shared/resources/lib.index.cache \
    && mkdir -p /home/default \
    && mkdir /output \
    && chmod -t /output \
    && rm -rf /output \
    && ln -s $WLP_OUTPUT_DIR/defaultServer /output \
    && ln -s /opt/ibm/wlp/usr/servers/defaultServer /config \
    && ln -s /opt/ibm /liberty \
    && ln -s /opt/ibm/wlp/usr/shared/resources/lib.index.cache /lib.index.cache \
    && mkdir -p /config/configDropins/defaults \
    && mkdir -p /config/configDropins/overrides \
    && chown -R 1001:0 /config \
    && chmod -R g+rw /config \
    && chown -R 1001:0 /opt/ibm/helpers \
    && chmod -R g+rwx /opt/ibm/helpers \
    && chown -R 1001:0 /opt/ibm/fixes \
    && chmod -R g+rwx /opt/ibm/fixes \
    && chown -R 1001:0 /opt/ibm/wlp/usr \
    && chmod -R g+rw /opt/ibm/wlp/usr \
    && chown -R 1001:0 /opt/ibm/wlp/output \
    && chmod -R g+rw /opt/ibm/wlp/output \
    && chown -R 1001:0 /logs \
    && chmod -R g+rw /logs \
    && chown -R 1001:0 /etc/wlp \
    && chmod -R g+rw /etc/wlp \
    && chown -R 1001:0 /home/default \
    && chmod -R g+rw /home/default

#These settings are needed so that we can run as a different user than 1001 after server warmup
ENV RANDFILE=/tmp/.rnd \
    IBM_JAVA_OPTIONS="-Xshareclasses:name=liberty,nonfatal,cacheDir=/output/.classCache/ ${IBM_JAVA_OPTIONS}"

USER 1001

EXPOSE 9080 9443

ENV KEYSTORE_REQUIRED true

-ENTRYPOINT ["/opt/ibm/helpers/runtime/docker-server.sh"]
+ENTRYPOINT [""]
CMD ["/opt/ibm/wlp/bin/server", "run", "defaultServer"]

稼働確認

ビルドする。

docker build -t alpine-liberty:19.0.0.4-kernel .

イメージサイズを確認。ベースイメージの差がそのまま差となっている。

$ docker images
alpine-liberty                                       19.0.0.4-kernel     f29cdd50ed52        5 minutes ago       231MB
websphere-liberty                                    19.0.0.4-kernel     011f0f2d6f85        13 days ago         344MB
ibmjava                                              8-jre-alpine        f35f7da9ef45        2 weeks ago         210MB
ibmjava                                              8-jre               d4383cee406b        2 weeks ago         322MB
alpine                                               3.7                 6d1ef012b567        2 months ago        4.21MB
ubuntu                                               16.04               a3551444fc85        2 weeks ago         119MB
$

起動してみる。

$ docker run --rm -it alpine-liberty:19.0.0.4-kernel

Launching defaultServer (WebSphere Application Server 19.0.0.4/wlp-1.0.27.cl190420190419-0642) on IBM J9 VM, version 8.0.5.35 - pxa6480sr5fp35-20190418_01(SR5 FP35) (en_US)
[AUDIT   ] CWWKE0001I: The server defaultServer has been launched.
[AUDIT   ] CWWKE0100I: This product is licensed for development, and limited production use. The full license terms can be viewed here: https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/license/base_ilan/ilan/19.0.0.4/lafiles/en.html
[WARNING ] CWWKF0009W: The server has not been configured to install any features.
[AUDIT   ] CWWKF0011I: The defaultServer server is ready to run a smarter planet. The defaultServer server started in 3.142 seconds.

起動した。起動したけどちゃんと動くかは不明。Javaだから大丈夫そうだけれど、それ以外のユーティリティコマンドがダメとかあるかもしれない。

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0