doushao5047 2015-05-02 23:33
浏览 272
已采纳

使用Docker进行开发,我应该使用ADD还是VOLUME?

I'm starting to use Docker on projects, and the majority of these projects runs on PHP (some on Nginx/PHP-FPM, some on Apache/PHP as module).

The thing is: my brain can't understand when to use the ADD and VOLUME directives on the Dockerfile for the paths that holds the source code.

Here's what I want: to change a line of code, access the browser on the container port, and see the changes. And so on, until things run as expected and then I "add" the code to the machine and deploy it. It's how I think Docker runs. Am I wrong?

AFAIK, the ADD directive copies the files on the given path to the image, and the VOLUME directive just say that a given path will me mounted by|on the Host.

Things that run through my mind, so far:

  1. Add the source code files via ADD, and then user the "-v" switch on command line to mount the source code on the same path used on ADD.

  2. Use VOLUME, and deal with two different Dockerfiles: for development containers, and for testing/development, and build each one as needed (this thing I think is counterproductive, and my heart tells me that this is not how it should work).

Can someone help me with this? What my brain can't grasp, and I should do (and understand) to leverage my Docker knowledge?

  • 写回答

3条回答 默认 最新

  • doupao3662 2015-05-03 08:34
    关注

    Th official PHP image gives examples of the two possible workflows.

    For production you can have a Dockerfile that builds a container containing your code:

    FROM php:5.6-apache
    COPY src/ /var/www/html/
    

    whereas for development you run a container with a volume referencing the local file system:

    docker run -it --rm --name my-php-dev -v "$PWD/src":/var/www/html php:5.6-apache
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员