什么是一个好的docker webdev工作流程? [英] What would be a good docker webdev workflow?

查看:80
本文介绍了什么是一个好的docker webdev工作流程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种预感, docker 可以极大地改善我的webdev工作流程-但是我还没有完全掌握如何解决问题的方法。项目将docker添加到堆栈中。



基本软件堆栈如下所示:



软件




  • 提供自定义LAMP堆栈的Docker镜像




    • 带有多个模块的Apache

    • MYSQL

    • PHP

    • 某些CMS,例如银条


  • GIT




工作流程



我可以想象工作流程看起来像以下内容:



开发




  1. 编写 Dockerfile 定义了满足上述要求的LAMP容器

    • REQ:计算机应在启动后立即启动apache / mysql


  2. 构建docker镜像

  3. 将运行CMS所需的文件复制到例如〜/ dev / cmsdir

    • 放入〜/ dev / cmsdir / 在版本控制下


  4. 运行docker容器,然后以某种方式挂载〜/ dev / cmsdir 到容器上的 / var / www /

  5. 填充数据库

  6. / dev / cmsdir /
  7. 中工作
  8. 提交&关闭docker容器



部署




  1. 设置远程主机(例如,带有ansible)

  2. 将容器映像推送到远程主机

  3. 获取 cmsdir 通过git进行项目

  4. 运行docker容器,拉入数据库并将 cmsdir 挂载到 / var / www

现在,在纸上看起来一切都很好,但我不确定



问题:




  1. 在本地进行开发时,如何使数据库在容器实例的重新启动之间保持不变?还是我需要在旋转容器之前每次都运行sql-dump?


  2. 是否应该为db和apache服务器分别设置容器实例?还是为上述用例准备一个容器就足够了?


  3. 如果对数据库和服务器使用单独的容器,我如何自动旋转它们并


  4. 我实际上如何将 / dev / cmsdir / 装入容器中 / var / www / -目录?我是否应该为此使用数据卷


  5. 我错过任何陷阱了吗?有什么可以简化的吗?



解决方案


  1. 如果需要数据库持久性独立于CMS容器,您可以将一个容器用于MySQL,将一个容器用于CMS。在这种情况下,您可以使MySQL容器仍在运行,并且可以根据需要独立地多次重新部署CMS。


    用于开发-另一个选择是从您的数据库中映射mysql数据目录。使用数据量的主机/开发机器。这样,您可以使用git(在主机上)和重新加载管理mysql(在docker中)的数据文件。



  2. 是的,我认为您应该有一个单独的db容器。

    >

  3. 我只使用基本脚本:

     #!/ bin / bash 

    $ JOB1 =(docker run ... / usr / sbin / mysqld)
    $ JOB2 =(docker run ... / usr / sbin / apache2)
    echo MySql = $ JOB1,Apache = $ JOB2



  4. 是的,您可以使用data-volumes -v开关。我将其用于开发。您可以使用只读挂载,因此,如果需要的话,将不会对此目录进行任何更改(您的应用程序仍应将数据存储在其他位置)。

      docker run -v = / home / user / dev / cmsdir:/ var / www / cmsdir:ro image / usr / sbin / apache2 

    无论如何,对于最终部署,我将使用带有 ADD / home / user / dev / cmsdir / var / www / cmsdir


  5. 我不知道:-)




I have a hunch that docker could greatly improve my webdev workflow - but I haven't quite managed to wrap my head around how to approach a project adding docker to the stack.

The basic software stack would look like this:

Software

  • Docker image(s) providing custom LAMP stack

    • Apache with several modules
    • MYSQL
    • PHP
    • Some CMS, e.g. Silverstripe
  • GIT

Workflow

I could imagine the workflow to look somewhat like the following:

Development

  1. Write a Dockerfile that defines a LAMP-container meeting the requirements stated above
    • REQ: The machine should start apache/mysql right after booting
  2. Build the docker image
  3. Copy the files required to run the CMS into e.g. ~/dev/cmsdir
    • Put ~/dev/cmsdir/ under version control
  4. Run the docker container, and somehow mount ~/dev/cmsdir to /var/www/ on the container
  5. Populate the database
  6. Do work in /dev/cmsdir/
  7. Commit & shut down docker container

Deployment

  1. Set up remote host (e.g. with ansible)
  2. Push container image to remote host
  3. Fetch cmsdir-project via git
  4. Run the docker container, pull in the database and mount cmsdir into /var/www

Now, this looks all quite nice on paper, BUT I am not quite sure whether this would be the right approach at all.

Questions:

  1. While developing locally, how would I get the database to persist between reboots of the container instance? Or would I need to run sql-dump every time before spinning down the container?

  2. Should I have separate container instances for the db and the apache server? Or would it be sufficient to have a single container for above use case?

  3. If using separate containers for database and server, how could I automate spinning them up and down at the same time?

  4. How would I actually mount /dev/cmsdir/ into the containers /var/www/-directory? Should I utilize data-volumes for this?

  5. Did I miss any pitfalls? Anything that could be simplified?

解决方案

  1. If you need database persistance indepent of your CMS container, you can use one container for MySQL and one container for your CMS. In such case, you can have your MySQL container still running and your can redeploy your CMS as often as you want independently.

    For development - the another option is to map mysql data directories from your host/development machine using data volumes. This way you can manage data files for mysql (in docker) using git (on host) and "reload" initial state anytime you want (before starting mysql container).

  2. Yes, I think you should have a separate container for db.

  3. I am using just basic script:

    #!/bin/bash
    
    $JOB1 = (docker run ... /usr/sbin/mysqld)
    $JOB2 = (docker run ... /usr/sbin/apache2)
    echo MySql=$JOB1, Apache=$JOB2
    

  4. Yes, you can use data-volumes -v switch. I would use this for development. You can use read-only mounting, so no changes will be made to this directory if you want (your app should store data somewhere else anyway).

    docker run -v=/home/user/dev/cmsdir:/var/www/cmsdir:ro image /usr/sbin/apache2
    

    Anyway, for final deployment, I would build and image using dockerfile with ADD /home/user/dev/cmsdir /var/www/cmsdir

  5. I don't know :-)

这篇关于什么是一个好的docker webdev工作流程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆