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.

  • Restart Docker Container (Automatically) when Image changes in Portainer(?)
  • Docker can't connect containers
  • Authorization settings problems for tomcat while deploying with docker
  • Containers are not linked with docker-compose version 2
  • Odd behaviour of dnsmasq across docker containers
  • Is there a way to discover other containers on a docker network using DNS?
  • 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 make opencv processing distributed on many hosts
  • Not able to connect to AS in Docker container
  • golang - weird characters using io.Copy to copy from bufio.Reader to STDOUT
  • Docker Error response from daemon: service endpoint with name.
  • how is cluster IP in kubernetes-aws configured?
  • Is s3fs not able to mount inside 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.