Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

198
Views
Docker workflow for automated builds on Github-Dockerhub

I already have set up a github repository with 3 branches (master, dev and docker). I already set up successfully and linked the automated build on dockerhub. Each time a push is done on Github an image is built on Dockerhub with different tag (latest for master, beta for dev and alpha for docker). This is working fine. Now the problem...

On Dockerfile, there is a git clone command to retrieve the project. The problem is this is pointing to master always. So if I push something to docker branch for example (it builds image with alpha tag) the code of project on that image is the code of master and not code of branch docker which is the desired for this case.

If I modify the Dockerfile of branch docker (which generate alpha tagged image) and I put git clone -b docker ... the build is ok, but after all the tests, when I want to merge with a pull request from docker branch to dev branch for example, another updated is needed on dev to change the git clone command inside of Dockerfile to point to the right branch. And the same with a pull request from dev to master with the additional difficult of on this project the master branch is protected and I can't push directly to master... so after a pull request from dev to master I can't fix Dockerfile changing the Dockerfile to change git clone to point again to master.

Is there a way to have different branches with different tags on automated building without changing anything after pull requests from one to other branch? Thank you.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

When using automated builds, this is what happens;

  • Docker Hub (or Docker Cloud, which has some more advanced features) checks out the git commit that triggered the build
  • It builds the Dockerfile that you configured to build from in your automated build

From the above; you should not git clone inside your Dockerfile at all, because you'd be doing what's already done by the automated build. Simply do;

FROM some-base-image

# Copy your project's source into the image
COPY . /my-src
RUN do-something-with-the-source

Docker Cloud has advanced features, which allow you to run custom scripts at various stages of the automated build, using build phase hooks (documentation). This allows you (for example) to make "minimal" images by building your project in a "build image", then copying the generated code to a local directory, and building the final image from that.

edit

The Automatic build options on Docker Cloud has more features than Automatic Build on Docker Hub. For example, the Dockerfile to build, and the build-context can be set separately. This allows you to have a Dockerfile in a subdirectory, but use files outside of that subdirectory to be used as the build context. To do this, set the Dockerfile location to (e.g.) /docker/Dockerfile, and the buildcontext to /

enter image description here

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!