Skip to content

Instantly share code, notes, and snippets.

@jalvarezsamayoa
Created June 2, 2015 15:02
Show Gist options
  • Save jalvarezsamayoa/c6142a294a65aa5c27df to your computer and use it in GitHub Desktop.
Save jalvarezsamayoa/c6142a294a65aa5c27df to your computer and use it in GitHub Desktop.
# I build my image with the latest tag
docker build –t myapp:latest .
# get the image's id
export latest=“$(docker images | grep myapp:latest | head –n 1 | awk ‘{print $3}’)”
# now here comes the cool part, generate a tag for the image related to the current state of the repo
docker tag $latest “$(git rev-parse –q HEAD)” # sha of the commit
docker tag $latest “$(git describe —always —dirty —tags)” # tag
docker tag $latest “$(git rev-parse –q —abbrev-ref HEAD)” #branch
# now we upload all these to the registry
for image in $(docker images | grep myapp | awk ‘{print $1 “:” $2}’ | head –n 4) ; \
do docker push $image ;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment