Using docker during the development workflow

前端 未结 4 1550
無奈伤痛
無奈伤痛 2021-02-01 09:09

I\'m using boot2docker on OS X and cloned the following repo:

https://github.com/enokd/docker-node-hello

It basically has a Dockerfile and a very simple express

4条回答
  •  孤街浪徒
    2021-02-01 09:43

    Your question is really interesting, and (partially) not specifically related to Docker. Let me say that the main and final problem here is the use of a virtual machine.

    Tracking code changes on host computer can be a challenge when you use a VM (bare Virtualbox VM, Vagrant VM, Docker boot2docker VM...)

    The VM is a complete layer of abstraction between your Mac (where your code changes happen) and your application stack (here, the Docker container running on a tiny Linux VM).

    • You have to explicitly define a shared folder (NFS, ...) in Virtualbox, between your Mac and boot2docker. This shared folder would be the root of your code repository. That's the first step.

      Mac: /Users/You/stuff/approot ===> boot2docker: /something


    • Then, you would have to tell your Docker container to use a Volume (docker terminology), bound to boot2docker, and point your Docker application to it:
       docker run -v /something:/app/path/inside/docker -p 49160:8080 \
         -d gasi/centos-node-hello /usr/bin/node /app/path/inside/docker/index.js
    


    • Having NodeJs detecting files change is another challenge. You need an additional wrapper watching the filesystem and restarting Node upon code changes (Forever, Nodemon...).

    • And, after that since the changes don't occur on a local filesystem, but on a shared folder, you'll probably have to tell the Nodejs watcher (Forever/Nodemon/...) to use polling mode. It works (more or less) but will burn a lot of CPU.

提交回复
热议问题