Docker: build using git push instead of ADD . /myapp

Basically my Dockerfile looks like so:

FROM ruby:2.1.4
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev
RUN mkdir /myapp
WORKDIR /myapp
ADD Gemfile /myapp/Gemfile
RUN bundle install
ADD . /myapp

It is fine, but the last line ADD . /myapp is not very smart: it duplicates every local files, including <APP_ROOT>/log which contains 8GB of useless data.

  • Docker limit memory usage is not working
  • Wildfly/Jboss Docker Cluster using Docker-compose
  • Unable to push docker images to artifactory
  • Why does different container of same elasticsearch image on docker exits out?
  • Docker and Java IDE integration
  • make causes core dump when entering an existing container
  • On the other hand, git is perfectly configured to store only usefull data (thanks to .gitignore among other).

    Ain’t there a simple solution to make a git pull <local_files> master from the Docker to the host or something?

    Otherwise I could also pull from github but it adds external dependency.

  • How do I assign a port mapping to an existing Docker container?
  • Can't start docker
  • Does a docker container have its own TCP/IP stack?
  • GitLab CI pipeline with multi-container kubernetes pod
  • What are the correct Permissions for docker in docker as another user?
  • Browsersync within a Docker container
  • 2 Solutions collect form web for “Docker: build using git push instead of ADD . /myapp”

    It sounds like you might be looking for the .dockerignore file. Doing a git pull inside the image at build time doesn’t seem like a very deterministic solution.

    You could add git inside the docker image with

    apt-get install -y git

    Then a

    RUN git clone ....

    But, IMHO, I think it’s best to clean your app folder and then add it via the ADD docker command

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.