【问题标题】:Docker - Execute script on containerDocker - 在容器上执行脚本
【发布时间】:2021-05-17 05:47:30
【问题描述】:

我从 docker 开始。我需要使用我在本地存储上配置的 WildFly 服务器安装创建一个映像,这个 Wildfly 有一个运行在 80 port 上的 java 应用程序。 我想创建一个运行standalone.sh 文件的容器,我可以通过本地机器上的locahost url 访问它。

当我尝试访问bin 目录时,我认为它是可以的,但是当我执行standalone.sh 文件时,得到这个错误:

/bin/sh: ./standalone.sh: No such file or directory

如何创建镜像并运行容器?

这是图像结构:

/opt
├── DEJ_Wildlfy
    ├── wildfly-11.0.0.Final
        ├── appclient
        ├── bin
            ├── standalone.bat
            ├── standalone.conf
            ├── standalone.sh <--
            ├── ......          
        ├── .....

我的 Docker 文件

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
COPY wildfly-11.0.0.Final .
RUN chmod 777 -R /opt/DEJ_Wildfly/
RUN chmod +X -R /opt/DEJ_Wildfly/
#ENV JBOSS_HOME /opt/DEJ_Wildfly/wildfly-11.0.0.Final

WORKDIR /opt/DEJ_Wildfly/wildfly-11.0.0.Final/bin/
RUN pwd
RUN ls
CMD standalone.sh -b=0.0.0.0
RUN ./standalone.sh -b 0.0.0.0
CMD tail -f /var/log/syslog
#EXPOSE 80

图片创建日志docker build --tag wildfly_dej_website:2.0 .

Sending build context to Docker daemon  597.4MB
Step 1/14 : FROM centos
 ---> 300e315adb2f
Step 2/14 : RUN yum -y install java-11-openjdk
 ---> Using cache
 ---> f333f6149e02
Step 3/14 : RUN java -version
 ---> Using cache
 ---> 0110143899c7
Step 4/14 : RUN mkdir /opt/DEJ_Wildfly/
 ---> Running in 6ac37e57c9c0
Removing intermediate container 6ac37e57c9c0
 ---> 70331f8da178
Step 5/14 : WORKDIR /opt/DEJ_Wildfly/
 ---> Running in 9d6169492b25
Removing intermediate container 9d6169492b25
 ---> b597e72f443e
Step 6/14 : COPY wildfly-11.0.0.Final .
 ---> 44db2164e32f
Step 7/14 : RUN chmod 777 -R /opt/DEJ_Wildfly/
 ---> Running in f56c31767282
Removing intermediate container f56c31767282
 ---> 2a2e074ac50f
Step 8/14 : RUN chmod +X -R /opt/DEJ_Wildfly/
 ---> Running in 8fbfbade9abf
Removing intermediate container 8fbfbade9abf
 ---> dea87a4dc31c
Step 9/14 : WORKDIR /opt/DEJ_Wildfly/wildfly-11.0.0.Final/bin/
 ---> Running in 20dc329acd81
Removing intermediate container 20dc329acd81
 ---> 3fe555e41d7d
Step 10/14 : RUN pwd
 ---> Running in 1af150bd74bb
/opt/DEJ_Wildfly/wildfly-11.0.0.Final/bin
Removing intermediate container 1af150bd74bb
 ---> 998b9c9876a3
Step 11/14 : RUN ls
 ---> Running in d2ca989a5b0a
Removing intermediate container d2ca989a5b0a
 ---> a0dd9c8263ae
Step 12/14 : CMD standalone.sh -b=0.0.0.0
 ---> Running in 560a62f26227
Removing intermediate container 560a62f26227
 ---> ca1aed8ec311
Step 13/14 : RUN ./standalone.sh -b 0.0.0.0
 ---> Running in d9820e7fb967
/bin/sh: ./standalone.sh: No such file or directory
The command '/bin/sh -c ./standalone.sh -b 0.0.0.0' returned a non-zero code: 127

【问题讨论】:

  • 有什么特别的原因导致您不能使用官方的 Wildfly Docker 映像并在其中添加您的应用程序,如 here 所示?这将使它成为小菜一碟。
  • 我有一些配置(ssl证书,standalone.xml修改)在官方镜像上不知道怎么弄
  • 该错误的三个推测原因:文件错误地具有 DOS 行结尾;该文件引用了一个不在图像中的非标准外壳(特别是,基于 Alpine 的图像默认没有bash);该脚本没有设置“执行”权限位(尽管您更有可能收到“权限被拒绝”错误)。

标签: java docker jboss wildfly


【解决方案1】:

当您运行 docker build 时,您正在创建映像,您不想在创建映像期间运行 wildfly - CMD 命令指定在使用该映像启动容器时要运行的默认命令。

有什么理由不使用 Wildfly 已经存在的 docker hub 镜像? https://hub.docker.com/r/jboss/wildfly

您可以在此处查看他们的 Dockerfile:https://github.com/jboss-dockerfiles/wildfly/blob/master/Dockerfile

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-04
    • 1970-01-01
    相关资源
    最近更新 更多