Docker git clone on container start?

My real understanding is that Docker executes any RUN git clone commands during docker build , and therefore the code base for my application is β€œbaked” in the Docker image.

How can I run git clone when the container starts?

Or is it considered bad practice and an anti-pattern?

The idea is that I don’t want every time I make any changes to my git registry, I don’t need to update my version of the Docker image.

+5
source share
1 answer

A common design pattern is to clone and compile your project as you build your Docker image. In addition, you can configure your image as a Docker Automated Build , which is defined in the Docker documentation as:

Automated assemblies are a feature of the Docker Hub that allows you to use Docker Hub clusters to automatically create images from the specified Docker file and the GitHub or Bitbucket repository (or "context"). The system will clone your repository and build the image described by the Dockerfile, using the repository as context. The resulting auto image will be uploaded to the Docker Hub registry and marked as auto build.

Auto build starts anytime when you commit (and click) into the repo branches that you specify. If this fails too often, perhaps you should point to another branch.

In any case, if you decide to launch the git clone when starting a new container, you can configure your Docker file using CMD ["my-script"] , being CMD ["my-script"] script with any bash script with the code you want.

+5
source

Source: https://habr.com/ru/post/1210156/


All Articles