title: How to build a docker container for a synchronized source code?
body: <p>I want to build a container for nodejs-bower-grunt but keeping my source code synchronized with the git repository (Bitbucket in this case). The idea is to provide a container to my team so that each one of the developers does not need to install these bunch of packages in their environments. Instead of installing nodejs, bower and grunt to run the front end of the app, they just use a container to manage them and focus on the source code. So this is my DockerFile:</p>
  
  <pre><code>FROM    ubuntu:14.04
  
  RUN     apt-get update
  RUN     apt-get install -y nodejs npm git git-core
  RUN     ln -s /usr/bin/nodejs /usr/bin/node
  
  WORKDIR /app
  
  ADD package.json /app/
  ADD bower.json .bowerrc* /app/
  
  RUN     npm install -g bower 
  RUN     npm install -g grunt-cli
  RUN     npm install 
  RUN     bower install --allow-root
  
  CMD ["grunt", "serve"]
  
  EXPOSE 9000
  EXPOSE 35729    
  </code></pre>
  
  <p>So I build the container and then run using this code:</p>
  
  <pre><code>docker run -ti -p 9000:9000 -p 35729:35729 -d -v /home/MY_USER/Projects/app:/app --name app --net=host my_repository/app
  </code></pre>
  
  <p>expecting that the VOLUME parameter would inject the source code into /app folder in the container without replacing all the stuffs previously configured in the DockerFile. According to the <a href="https://docs.docker.com/engine/tutorials/dockervolumes/#/mount-a-host-directory-as-a-data-volume" rel="nofollow">official documentation</a>, the contents were supposed to be kept:
  "<em>the /src/webapp mount overlays but does not remove the pre-existing content</em>", but it turns out that when I check the running container, the contents mounted by the DockerFile are replaced by the -v folder contents passed by parameter. One solution would be copy all the app contents to the container itself and then run the container but this solution would be impractical for a developing project, as every update in the app would require building another container. So, my question is: How can I build this container in such a way that every update in the host source code would reflect the running container ? </p>