gpt4 book ai didi

docker - 如何在不出错的情况下扩展nginx docker镜像systemctl:找不到命令?

转载 作者:行者123 更新时间:2023-12-02 18:51:28 25 4
gpt4 key购买 nike

我想从nginx镜像构建自己的自定义docker镜像。

我用自己的ENTERYPOINT文件覆盖了Nginx的ENTRYPOINT。

这给我带来了两个问题:

  • 我认为这样做会丢失Nginx的一些命令。我对吗? (例如暴露端口。)
  • 如果要重新启动Nginx,请运行以下命令:nginx -t && systemctl reload nginx。但输出是:
    nginx: configuration file /etc/nginx/nginx.conf test is successful/entrypoint.sh: line 5: systemctl: command not found

  • 如何解决?
    FROM nginx:latest

    WORKDIR /

    RUN echo "deb http://ftp.debian.org/debian stretch-backports main" >> /etc/apt/sources.list

    RUN apt-get -y update && \
    apt-get -y install apt-utils && \
    apt-get -y upgrade && \
    apt-get -y clean

    # I ALSO WANT TO INSTALL CERBOT FOR LATER USE (in my entrypoint file)

    RUN apt-get -y install python-certbot-nginx -t stretch-backports

    # COPY ./something ./tothisimage
    # COPY ./something ./tothisimage
    # COPY ./something ./tothisimage
    # COPY ./something ./tothisimage

    COPY entrypoint.sh /entrypoint.sh

    ENTRYPOINT ["bash", "/entrypoint.sh"]

    entrypoint.sh
    echo "in entrypoint"

    # I want to run some commands here...

    # After I want to run nginx normally....

    nginx -t && systemctl reload nginx

    echo "after reload"

    最佳答案

    这将使用service命令起作用:

    echo "in entrypoint"

    # I want to run some commands here...

    # After I want to run nginx normally....

    nginx -t && service nginx reload

    echo "after reload"

    输出:
    in entrypoint
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    Restarting nginx: nginx.
    after reload

    关于docker - 如何在不出错的情况下扩展nginx docker镜像systemctl:找不到命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58429232/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com