简体   繁体   中英

Continous development with Docker containers

I'm using docker for a new project for learning purposes. I thought that it would make things a lot easier since I have to setup the environment only once.

I've created a setup like this; I created a base image that installs Ubuntu and NodeJS. I've also created a Development image that copies a src (web application) folder into the container, then does an npm install and runs the server.js . That's basically it in a nutshell.

But now, whenever I make a change to my source code I have to stop the running container, and build the image and run it again. It doesn't take long to rebuild and run de Development image, but it gets a bit annoying to do that eveythime I make a change to my code during development.

What I normally had was a Gulp task or Browsersync watching my local files. Everytime I made a change, those changes were automatically visible in the browser. That really speeds up the development process.

I could still work like this during development by installing everything locally. But that kinda defeats the purpose of having a "development image". That means that I still have to configure all the systems that want to work on this web application with the appropiate Node version, Database schemes, port mappings, SSL settings, Certificats etc.

So my questions is, is there a way to run a container, and whenever I change the source code (locally), that it is then automatically pushed to the running container? So I have "continuous development"?

If I understood you correctly, you don't wish to build the Development image each time you update the src. If that's the situation, what you can do is:

For the Development Phase (When the Source code is update frequently):

  1. Create a Dockerfile in such a way that make use of a shared volume (where the source code will reside).
  2. In the shared volume, you can update the source code using the src container.
  3. Also, if you need to do some additional task, you can write it in a script and call that script each time you update the source.

Later on, when the development phase ends, you may use your current Dockerfile to build the development image.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM