I dockerized my app, but in order to see my changes, I would have to rebuild my image and it wouldn't give me a live preview of my app.
So I created a docker-compose environment which links redis to my a node container, and then mounts the source code from the host to the node app and watches it for changes. However, since the code isn't part of UnionFS, it can't be containerized.
How do I setup a development environment which can produce dockerized images but doesn't have to be restarted every time I make a change to the codebase?
The container image you develop with and mount directories in should be the same image you produce to run the app elsewhere, or at least based the production image if that can't be achieved.
Using a simple node app as an example, here is the base image:
Production
Development
So I've modified the mount, but the base image is the same. The mounted files replace the "built" files in the container.
In the case of a node.js application, there's a couple of extra development changes. An environment variable and the command used to watch/restart the process on changes. You also need to manually exec an
npm install
in the container withdocker exec $container npm install
when you make changes to the dependencies inpackage.json
.Development Dockerfile
If you require a number of modifications for a development environment and don't want to specify them manually you can create a development image
FROM
your base image that houses the development specifics.Dockerfile.dev
:Then the dev specifics are stored in the new image but still linked to your real image.