dpowhyh70416 2019-07-09 06:06
浏览 1111
已采纳

在Alpine上运行nginx

I would like to run nginx and php-fpm on container start, however I can't seem to do that. Here is my Dockerfile:

FROM php:7-fpm-alpine

EXPOSE 9080 8000
EXPOSE 9088 80

WORKDIR /var/www
COPY . .

RUN apk add nginx composer php7-fpm && \
    composer install --no-progress && \
    mkdir -p /etc/nginx /etc/nginx/sites-available /etc/nginx/sites-enabled /run/nginx && \
    ln -s /etc/nginx/sites-available/default.conf /etc/nginx/sites-enabled/default.conf && \
    cp nginx.conf /etc/nginx/conf.d/default.conf

CMD ["nginx", "-g", "daemon off;"]

Container comes up and running, however when I run ps aux nginx is nowhere to be seen until I run nginx command (configuration is okay, nginx -t returns okay, and running it through open container does start the service).

I've tried to chain RUN php-fpm7 && nginx but that does nothing.

Also using entrypoint like ENTRYPOINT ["nginx"] did nothing for me.

How can I make sure those processes are running upon creating the container?

  • 写回答

3条回答 默认 最新

  • donglinyi4313 2019-07-09 06:48
    关注

    you can add a script and use it in your CMD:

    script :

    #!/bin/bash
    service nginx start
    php-fpm7
    

    add the script to your Dockerfile:

    COPY /PATH/TO/script.sh /path/in/container/script.sh
    RUN chmod +x /path/in/container/script.sh
    CMD ["/path/in/container/script.sh"]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵