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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With