dongzi1959 2017-04-25 22:06
浏览 96
已采纳

Docker生产准备好php-fpm和nginx配置

I have a small theoretical problem with combination of php-fpm, nginx and app code in Docker.

I'm trying to stick to the model when docker image does only one thing -> I have separate containers for php-fpm and nginx.

php:
    image: php:5-fpm-alpine
    expose:
        - 9000:9000
    volumes:
        - ./:/var/www/app

nginx:
    image: nginx:alpine
    ports:
        - 3000:80
    links:
        - php
    volumes:
        - ./nginx/app.conf:/etc/nginx/conf.d/app.conf
        - ./:/var/www/app

NOTE: In app.conf is root /var/www/app; Example schema from Symfony

This is great in development, but I don't know how to convert this to production ready state. Mount app directory in production is really bad practice (if I'm not wrong). In best case I copy app source code into container and use this prebuilded code (COPY . /var/www/app in Dockerfile), but in this case is impossible or I don't know how.

I need share app source code between two contatiner (nginx container and php-fpm container) because booth of that need it.

Of course I can make own nginx and php-fpm container and add COPY . /var/www/app into both of them, but I thing that is wrong way because I duplicate code and the whole build process (install dependencies, build source code, etc...) must be in both (nginx/php-fpm) containers.

I try to search but I don't find any idea how to solve this problem. A lot of articles show how to do this with docker-compose file and mount code with --volume but I didn't find any example how to use this on production (without volume).

Only one acceptable solutions for me (in this time) is make one container with nginx and php-fpm together but I'm not sure when is a good way (I try to find best practice).

Do you have any experiences with this or any idea how to solve it?

Thanks for any response!

  • 写回答

2条回答 默认 最新

  • ds3464 2017-05-02 18:13
    关注

    At this time I use smth like:

    Dockerfile:

    FROM php:fpm
    COPY . /var/www/app/
    WORKDIR /var/www/app/
    RUN composer install
    EXPOSE 9000
    VOLUME /var/www/app/web
    

    Dockerfile.nginx

    FROM nginx
    COPY default /etc/nginx/default
    

    docker-compose.yml

    app:
      build:
        context: .
    web:
      build:
        context: .
        dockerfile: Dockerfile.nginx
      volumes_from: app  
    

    But in few days on 17.05 release we can do in one Dockerfile smth like:

    FROM php:cli AS builder
    COPY . /var/www/app/
    WORKDIR /var/www/app/
    RUN composer install && bin/console assets:dump
    
    FROM php:fpm AS app
    COPY --from=builder /var/www/app/src /var/www/app/vendor /var/www/app/
    COPY --from=builder /var/www/app/web/app.php /var/www/app/vendo /var/www/app/web/
    
    FROM nginx AS web
    COPY default /etc/nginx/default
    COPY --from=builder /var/www/app/web /var/www/app/web
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 lvm2被mask了,怎么unmask都没用(标签-ubuntu|关键词-apt)
  • ¥15 交叉注意力机制的残差问题
  • ¥15 微信小程序:渲染收货地址时页面不显示
  • ¥20 win7 64位DirectShow提示初始化失败如何解决?
  • ¥20 小规模孤立词识别系统设计
  • ¥15 关于Java对接海康威视车牌识别一体机SDK是否需要固定外网的IP?
  • ¥15 Linux扩容时,格式化卡住了:vgdispaly查看卷组信息,没有输出
  • ¥18 关于#ubuntu#的问题:使用背景-工作职责内有七八台ubuntu系统的电脑,平时需要互相调取资料,想实现把这几台电脑用交换机组成一个局域网,来实现指定文件夹的互相调取和写入
  • ¥20 求一个简易射频信号综测仪
  • ¥15 esp8266 tally灯 接收端改为发射端