1

我尝试为 EMQ MQTT 服务器构建自定义镜像。但是脚本 update_config.sh 在 docker copmose up 期间不会执行。

Dockerfile:

FROM emqttd-docker-v2.3.5

# change configuration file
ADD update_config.sh /opt/emqttd/etc/update_config.sh
ADD ./certs/MyEMQ1.key /opt/emqttd/etc/certs/MyEMQ1.key
ADD ./certs/MyEMQ1.pem /opt/emqttd/etc/certs/MyEMQ1.pem
ADD ./certs/MyRootCA.pem /opt/emqttd/etc/certs/MyRootCA.pem


WORKDIR /opt/emqttd/etc/

#update the emqtt config file
RUN /bin/ash -c /opt/emqttd/etc/update_config.sh

update_config.sh

#!/bin/ash

cd /opt/emqttd/etc
cp ./emq.conf ./emq.conf.bak
sed -i 's|.*listener.ssl.external.keyfile.*|listener.ssl.external.keyfile = etc/certs/MyEMQ1.key|g' ./emq.conf
sed -i 's|.*listener.ssl.external.certfile.*|listener.ssl.external.certfile = etc/certs/MyEMQ1.pem|g' ./emq.conf
sed -i 's|.*listener.ssl.external.cacertfile.*|listener.ssl.external.cacertfile = etc/certs/MyRootCA.pem|g' ./emq.conf
sed -i 's|.*listener.ssl.external.verify.*|listener.ssl.external.verify = verify_peer|g' ./emq.conf

我使用 docker-compose 来构建图像。update_config.sh 脚本被复制到映像中,但未执行。

到目前为止我尝试了什么:

  • 使用 COPY 而不是 ADD 来复制文件
  • 尝试了RUN /bin/ash -c /opt/emqttd/etc/update_config.sh以下口味:
    • RUN /bin/ash -c /opt/emqttd/etc/update_config.sh
    • RUN /opt/emqttd/etc/update_config.sh
    • RUN ./update_config.sh
  • 试图在导致错误RUN chmod +x /opt/emqttd/etc/update_config.sh的行之前添加chmod: /opt/emqttd/etc/update_config.sh: Operation not allowed during buildRUN /bin/ash -c /opt/emqttd/etc/update_config.sh

谁能帮我?谢谢。

4

2 回答 2

2

Just add ENTRYPOINT ["/bin/bash", "update_config.sh" ] this as your last line. And also update_config.sh file to start your application and make your container in infinite loop.

Example update_config.sh:

    #!/bin/ash

    cd /opt/emqttd/etc
    cp ./emq.conf ./emq.conf.bak
    sed -i 's|.*listener.ssl.external.keyfile.*|listener.ssl.external.keyfile = etc/certs/MyEMQ1.key|g' ./emq.conf
    sed -i 's|.*listener.ssl.external.certfile.*|listener.ssl.external.certfile = etc/certs/MyEMQ1.pem|g' ./emq.conf
    sed -i 's|.*listener.ssl.external.cacertfile.*|listener.ssl.external.cacertfile = etc/certs/MyRootCA.pem|g' ./emq.conf
    sed -i 's|.*listener.ssl.external.verify.*|listener.ssl.external.verify = verify_peer|g' ./emq.conf
    sh start_your_app.sh
    touch 1.txt;tail -f 1.txt #This will make your container in running infinite so that even after all the steps of this script has been executed your container will continue running. until you kill tail -f 1.txt command.

Hope this will help. Thank you!

于 2018-03-12T08:46:40.720 回答
0

灰 - 是最小的贝壳之一。这个命令解释器有 24 个内置命令和 10 个不同的命令行选项。

ash 没有您需要的所有命令。你应该使用/bin/bash

于 2018-03-12T08:41:49.473 回答