Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker git clone on container launch?

Tags:

git

docker

My current understanding is that Docker executes any RUN git clone commands during docker build and thus the codebase for my app is 'baked in' to the Docker image.

How would I go about running the git clone when the container launches?

Or is this considered bad practice and anti-pattern?

The idea being that I don't want to have to uptick my Docker image version every time I make any changes to my git repo.

like image 771
AJB Avatar asked Dec 31 '14 04:12

AJB


1 Answers

The common design pattern is clonning and compiling your project in the Docker image build process. In addition, you can configure your image as a Docker Automated Build, which is defined in Docker documentation as:

Automated Builds are a special feature of Docker Hub which allow you to use Docker Hub's build clusters to automatically create images from a specified Dockerfile and a GitHub or Bitbucket repo (or "context"). The system will clone your repository and build the image described by the Dockerfile using the repository as the context. The resulting automated image will then be uploaded to the Docker Hub registry and marked as an Automated Build.

The automated build is launch anytime you do a commit (and a push) in the branch of the repo you are pointing. If it is triggered too often maybe you should point to other branch.

Anyway, if you choose to run the git clone when you run a new container, you can configure your Dockerfile with CMD ["my-script"], being my-script any bash script with the code you wish.

like image 72
Javier Cortejoso Avatar answered Oct 24 '22 17:10

Javier Cortejoso