doukougua7873 2015-06-04 12:38
浏览 61

生产中的Docker和包管理器

I'm developing a PHP application which I want to have running using docker containers. I'm using the composer package manager which pulls in all the dependencies. All code is kept in a git repository except the dependencies.

To get everything running on my local machine I'm using docker-compose (fig). I mount my application code (include vendor folder) to volume on my containers. Here is my docker-compose.yml file.

nginx:
    image: nginx:1.9
    links:
        - php
    volumes:
        - conf/nginx/default.conf:/etc/nginx/conf.d/default.conf
        - src:/var/www/html
    ports:
        - "80:80"
php:
    image: php:5.6.9-fpm
    links:
        - memcached
    volumes:
        - conf/php/php.ini /usr/local/etc/php/php.ini
        - src:/var/www/html
    volumes_from:
        - nginx

What I don't really understand is how I would push this into production or staging environment. From what I understand it's best to ship everything in a container without having to run a package manager, because this might fail or the packages might not be identical as the packages on my local machine. So I Came up with the following docker-compose.yml file:

webapp:
    image : quay.io/myusername/myrepo
php:
    image: php:5.6.9-fpm
    volumes:
        - config/php/php.ini /usr/local/etc/php/php.ini
    volumes_from:
        - webapp
nginx:
    image: nginx:1.9
    links:
        - php
    volumes:
        - config/nginx/default.conf:/etc/nginx/conf.d/default.conf
    volumes_from:
        - webapp
    ports:
        - "80:80"

The webapp container is build from the following dockerfile and is hosted on some repository.

FROM busybox

VOLUME /var/www/html
ADD src /var/www/html

I have a git hook that will trigger a build of this dockerfile on quay.io and adds my source code to the image.

Here's the problem: The vendor files / dependencies are not in version control so they won't be added.

I see two solutions which I both don't find ideal.

  1. Add the dependencies to version control.
  2. Run command composer install to pull in all files. Not preferable as mentioned above.

I'm still very new to docker, so it could be I got things all wrong. Would love to get an answer how to do this properly.

  • 写回答

1条回答 默认 最新

  • dongzhenyin2001 2015-06-04 13:10
    关注

    Your Dockerfile should build the container image as if there would be no volumes mounted. Clone or copy your code in the container, run composer to install dependencies. Running the container without any volumes should work.

    Volumes in production environments are for persisting data and logs primarily. Your code should not be in a mounted volume.

    For development purposes, you can mount a volume to the code location and your container will still work.

    To speed up the build process, copy your composer.json and composer.lock files first and install dependencies to a location outside your source tree. It will ensure the dependencies only get updated when your json file changes, not on every code change, speeding up the process immensely.

    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧