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.

  • Updating code in a docker container
  • Error: duplicated outer port
  • HTTP response 403 when trying to push to registry
  • “Plugging in” Docker Container to Host Network
  • Docker - Node.js + MongoDB - “Error: failed to connect to [localhost:27017]”
  • Production vs Development Docker setup for Node (Express & Mongo) App
  • 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.

  • Docker: cannot use postgres client connect to database container
  • Change Docker backoff time
  • why docker not executing init as lxc
  • Mixed binary log by default
  • Trying to run Cloudera Image in Docker
  • Dockerfile custom commands/directives
  • 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.