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.

  • Differences in the ways of creating a Docker swarm
  • Kubernetes error pulling of local registry
  • How to deploy docker container image updates from AWS ECR to ECS?
  • How to Distribute Jenkins Slave Containers Within Docker Swarm
  • Create Docker-Machine without re-provisioning Docker
  • Openshift pods crash
  • 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 to create postgis extension for postgresql in docker?
  • Docker and high performance cluster (HPC) ability
  • Are docker images portable across different linux flavours?
  • Docker Mount an entire mounted host partition as a data volume
  • Running a longer command from docker
  • Error Connecting to Docker hub
  • 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.