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

标签 docker nginx

我想从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/

    相关文章:

    spring-boot - 无法在 docker 上运行 JavaFX 应用程序超过几分钟

    docker - libGL错误:无法加载驱动程序:swrast-在Mac OS X主机上运行Ubuntu Docker容器

    reactjs - 将使用 vite 和基本名称构建的 React 应用程序部署到 NGinx

    nginx - .wellknown 文件夹权限被拒绝 nginx

    ruby-on-rails - 备份 CentOS Web 服务器并将其安装在本地机器上

    apache - 站点文件夹的 www-data 和组读取问题

    node.js - Docker-撰写我无法创建Postgres服务器

    linux - 将 Docker 镜像中的用户切换为非 root 用户

    mysql - 带有 Centos7 的 NGINX 上的 phpmyadmin 显示空白页面?

    mongodb - 如何为 MEAN 应用程序编写集成测试