In our jenkins2 pipeline we use docker-compose for some of our tests and our docker-compose file gets its network name from a combination of the branch name (git) and its build number.
Jenkins file fragment:
def version = "$BRANCH_NAME-$BUILD_NUMBER"
def networkName = "network-$version"
sh "NETWORK_NAME=$networkName docker-compose up -d"
docker-compose.yml fragment:
version: '3.5'
networks:
default:
name: ${NETWORK_NAME}
driver: bridge
It looks like when we have a short branch name everything goes fine and when we have a long branch name it fails.
How long can the network name be in docker-compose? I can't seem to find it in the documentation. Is there a better solution to get unique network names than going for the branch name?
I've tried this but it seems totally overkill somehow:
echo $(git rev-parse --abbrev-ref HEAD) | md5 | cut -f1 -d" "
will give md5 result.
So after not having had an answer after a few days I did some empirical testing of my own and found out that it is different for different OS's. I wanted to write my answer down for others with the same problem.
Here is what I found:
/
chars in itSo if you want to be save and have your docker-compose.yml work on different environments you should stick to a network name with a max length of 15 chars.
Also used this answer: What length can a network interface name have?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With