I have a tool written in perl which deploys Java applications with a specific revision to remote servers like tomcat or wildfly/JBoss.
Therefore the tool need to connect to wildfly and after to the maschine where wildfly is running with ssh.
I want to dockerize this whole process. So my deploymenttool should run in a container and the remote server should be dockerized, too.
Is there a way to run wildfly and ssh in one container so it can depict a server?
I tried to dockerize the server with the following Dockerfile but I had no success with it
## SELECT IMAGE
FROM ubuntu:18.04
RUN apt-get update && \
apt-get upgrade -y && \
apt install -y openjdk-11-jdk && \
apt install -y subversion && \
apt install -y openssh-server && \
apt install -y wget
RUN mkdir /var/run/sshd
RUN sed -i 's/#*PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
RUN sed -i 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' /etc/pam.d/sshd
ENV NOTVISIBLE="in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
RUN useradd -ms /bin/bash user
RUN usermod -aG sudo user
## SET JAVA ENV
ENV JAVA_HOME /usr/lib/jvm/java-11-openjdk-amd64
## COPY CONF FILES TO ROOT
COPY conf/root/ssh/ /root/.ssh/
COPY conf/root/subversion/auth /root/.subversion/auth
## INSTALL JBOSS
RUN wget -O /tmp/wildfly-16.0.0.Final.tar.gz \
https://download.jboss.org/wildfly/16.0.0.Final/wildfly-16.0.0.Final.tar.gz && \
tar zxvf /tmp/wildfly-16.0.0.Final.tar.gz -C /opt
## JBOSS CONFIG
RUN sed -i -r 's/jboss.bind.address.management:127.0.0.1/jboss.bind.address.management:0.0.0.0/' \
/opt/wildfly-16.0.0.Final/standalone/configuration/standalone.xml
## CLEAN JBOSS
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
USER root
EXPOSE 8080 9990
EXPOSE 22
CMD /usr/sbin/sshd
RUN /opt/wildfly-16.0.0.Final/bin/add-user.sh --silent=true admin admin
CMD /opt/wildfly-16.0.0.Final/bin/standalone.sh -b=0.0.0.0
The wildfly server is running and I can access it. This is working perfectly. But ssh isn't working.
Docker is meant to be used to create application containers - that is containers with a single service inside. Because of this only the last CMD
is taken into consideration when building the image. If you do docker inspect image_name
, you'll see that your image has its command set to /opt/wildfly-16.0.0.Final/bin/standalone.sh -b=0.0.0.0
.
It is possible (but not advised) to work around this limitation by adding a supervisory service that starts, stops and monitors other services. The details of this approach are listed in the official documentation.