Part of our CI/CD workflow tags Docker images with the git branch's name. However, the set of valid characters for docker tags is smaller than the set of valid characters for a git branch name.
As a very simple example, the branch name bugfix/my_awesome_feature
is not a valid tag:
docker build . -t image_name:$(git rev-parse --abbrev-ref HEAD)
Fails with the error that it is "not a valid repository/tag: invalid reference format".
Same with more complicated branch names: fix/bug#123
, pr@123
, etc....
What's the best way to turn a git branch name into a valid docker tag? Ignoring or replacing all invalid characters is fine.