2

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.

Ivonet
  • 2,492
  • 2
  • 15
  • 28

1 Answers1

6

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:

  • docker on a mac mac can have very long network names and can even have / chars in it
  • some linux distributions can have 16 chars (e.g. CentOs) and others 15 (e.g. Ubuntu).
  • couldn't test on Windows as I have none available

So 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?

Ivonet
  • 2,492
  • 2
  • 15
  • 28