Preferred method for Docker File Versioning

0 votes

I simply want to know how best to user docker with git? We're a team of 6. We want to make sure that everyone is using the same libraries and dependencies. We're using docker to compile our source in the localhost. Just want to know how best to do the versioning?

  1. Add the Dockerfile to the source code repository
  2. Create a dedicated repository for all our Dockerfiles
  3. Created a dedicated repository for each Dockerfile
  4. Others?
Jun 11, 2018 in Docker by Atul
• 10,240 points
1,237 views

1 answer to this question.

0 votes

Use labels to add versioning information to the docker image. Keep the dockerfile and the source code together.

  • the git commit and branch
  • whether it's "dirty" meaning that changes were made locally on the src code from what's in git
  • a CI version number (publicly visible)
  • the person who built the image (not the person who last checked in git)

Add the commit number to the image. Here's a sample of what it would be like:

build-image.sh

echo '===> Building docker image...'

GIT_BRANCH=$(git name-rev --name-only HEAD | sed "s/~.*//")
GIT_COMMIT=$(git rev-parse HEAD)
GIT_COMMIT_SHORT=$(echo $GIT_COMMIT | head -c 8)
GIT_DIRTY='false'
BUILD_CREATOR=$(git config user.email)
BUILD_NUMBER="${BUILDKITE_BUILD_NUMBER-0}"
# Whether the repo has uncommitted changes
if [[ $(git status -s) ]]; then
    GIT_DIRTY='true'
fi

docker build \
  -q \
  -t quay.io/myco/servicename:latest \
  -t quay.io/myco/servicename:"$GIT_COMMIT_SHORT" \
  --build-arg GIT_BRANCH="$GIT_BRANCH" \
  --build-arg GIT_COMMIT="$GIT_COMMIT" \
  --build-arg GIT_DIRTY="$GIT_DIRTY" \
  --build-arg BUILD_CREATOR="$BUILD_CREATOR" \
  --build-arg BUILD_NUMBER="$BUILD_NUMBER" \
  .

echo "Done"
echo "Push to quay using:"
echo "  docker push quay.io/myco/servicename:latest"
echo "  docker push quay.io/myco/servicename:$GIT_COMMIT_SHORT"

Dockerfile

FROM ...

ARG GIT_COMMIT
ARG GIT_BRANCH=master
ARG GIT_DIRTY=undefined
ARG BUILD_CREATOR
ARG BUILD_NUMBER

LABEL branch=$GIT_BRANCH \
    commit=$GIT_COMMIT \
    dirty=$GIT_DIRTY \
    build-creator=$BUILD_CREATOR \
    build-number=$BUILD_NUMBER

... etc

You can then write scripts to check for the version of the image

docker inspect --format "{{.ContainerConfig.Labels.commit}}" imageid
answered Jun 11, 2018 by ajs3033
• 7,300 points

Related Questions In Docker

0 votes
1 answer

Where can I find Docker log (driver json-file) location for ‘Docker for windows’?

For windows, the container storage is the ...READ MORE

answered Aug 16, 2018 in Docker by Sophie may
• 10,610 points
2,069 views
0 votes
1 answer

Is it possible to use JSON instead of YAML for docker-compose file?

You can use JSON instead of YAML ...READ MORE

answered Jul 2, 2019 in Docker by Sirajul
• 59,230 points
4,412 views
+6 votes
4 answers

Error: Docker saying "bad file descriptor"

The solution was easy enough. Add these ...READ MORE

answered Mar 27, 2018 in Docker by DragonLord999
• 8,450 points
6,662 views
+4 votes
7 answers

If conditional in docker file

First of all, create a build_internal.sh file ...READ MORE

answered May 29, 2018 in Docker by DareDev
• 6,890 points
120,197 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
3,498 views
+2 votes
1 answer
0 votes
2 answers

Can't access apache karaf docker container

To access karaf shell directly you can ...READ MORE

answered Aug 6, 2018 in Docker by Nilesh
• 7,050 points
2,112 views
0 votes
1 answer

Unable to switch filesystem to overlay in Docker in Ubuntu.

From the official docs: https://docs.docker.com/engine/userguide/storagedriver/overlayfs-driver/#configure-docker-with-the-overlayoverlay2-storage-driver To configure Docker ...READ MORE

answered Jul 18, 2018 in Docker by ajs3033
• 7,300 points
2,507 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP