繁体   English   中英

Docker - 独立运行 Wildfly

[英]Docker - Run Wildfly standalone

我有一个 Ubuntu 服务器,配置了 WildFly 独立安装,这里我有一个 Java 应用程序可在端口 80 上访问,我想将其 docker 化。 创建容器时,我将整个 WildFly 目录从本地存储复制到容器,当我运行命令docker run -d --name dej_website -p 80:80 wildfly_dej_website:2.0容器启动时,但是当尝试在我的本地机器localhost中的访问不起作用。

我究竟做错了什么? 如何使用已配置的服务器访问此容器?

这是我的 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

这是docker build --tag wildfly_dej_website:2.0. 命令:

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

这是容器列表:

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

这里的问题出在您的 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.

在您的 dockerfile 中添加这样的行:

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

为了使端口在本地机器上可访问,您需要在发出docker run命令时使用-p选项,如下所示:

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

你可以在这里找到更多信息: https://docs.docker.com/engine/reference/commandline/run/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM