Docker - Run Wildfly standalone

Viewed 459

I have a Ubuntu server with a WildFly standalone installation configured, here i have a Java app that is accesible on port 80, i want to dockerize it. When create the container, i'm copying the entire WildFly directory from my local storage to the container, when i run the command docker run -d --name dej_website -p 80:80 wildfly_dej_website:2.0 the container start, but when try to access in my local machine localhost doesn't works.

What am i doing wrong? How can i do to access to this container, with the configured server?

This is my dockerfile

FROM centos

#INSTALL JAVA
RUN yum -y install java-11-openjdk
RUN java -version

RUN mkdir /opt/DEJ_Wildfly/

#SET OPT AS WORK DIRECTORY
WORKDIR /opt/DEJ_Wildfly/

#COPY WILDFLY SERVER FILES
COPY wildfly-11.0.0.Final .

#DEFINE ENVIRONMENT VARIABLE
ENV JBOSS_HOME /opt/DEJ_Wildfly/wildfly-11.0.0.Final/

#EXECUTE SH FILE
CMD JBOSS_HOME/bin/standalone.sh -b=0.0.0.0
CMD tail -f /var/log/lastlog
#EXPOSE 80

This is the log of docker build --tag wildfly_dej_website:2.0 . command:

Sending build context to Docker daemon  597.4MB
Step 1/9 : FROM centos
---> 300e315adb2f
Step 2/9 : RUN yum -y install java-11-openjdk
---> Using cache
---> f333f6149e02
Step 3/9 : RUN java -version
---> Using cache
---> 0110143899c7
Step 4/9 : RUN mkdir /opt/DEJ_Wildfly/
---> Running in 88bc6f0632c1
Removing intermediate container 88bc6f0632c1
---> c0ab7cc8a364
Step 5/9 : WORKDIR /opt/DEJ_Wildfly/
---> Running in 84705355ac2c
Removing intermediate container 84705355ac2c
---> 6986f8229cb0
Step 6/9 : COPY wildfly-11.0.0.Final .
---> 3caf8ec0e5d0
Step 7/9 : ENV JBOSS_HOME /opt/DEJ_Wildfly/wildfly-11.0.0.Final/
---> Running in b5f649e4e2e0
Removing intermediate container b5f649e4e2e0
---> 27d775c3d0cb
Step 8/9 : CMD JBOSS_HOME/bin/standalone.sh -b=0.0.0.0
---> Running in c7ffddb4bcdf
Removing intermediate container c7ffddb4bcdf
---> 533d3836f94d
Step 9/9 : CMD tail -f /var/log/lastlog
---> Running in f92aca5a63ba
Removing intermediate container f92aca5a63ba
---> 974e6ec6c415
Successfully built 974e6ec6c415
Successfully tagged wildfly_dej_website:2.0

This is the list of containers:

CONTAINER ID   IMAGE                   COMMAND                CREATED       STATUS       PORTS              NAMES
95ee0139f42c   wildfly_dej_website:2.0 "/bin/sh -c 'tail -f…" 4 seconds ago Up 2 seconds 0.0.0.0:80->80/tcp dej_website
1 Answers

The problem here is in your dockerfile.

You need to add a CMD at the end of your dockerfile to run the command you want and keep it running for the docker file to stay alive and provide you with logs through docker logs command.

Add a line like this to your dockerfile:

RUN ./standalone.sh -b 0.0.0.0
CMD tail -f /var/log/syslog

And to make the port accessible on the local machine you'll need to use -p option when issuing the docker run command like this:

docker run -d -p 127.0.0.1:80:8080 <image>

you can find out more here: https://docs.docker.com/engine/reference/commandline/run/

Related