Compose: Allow hyphens (dashes) in COMPOSE_PROJECT_NAME

Created on 4 Oct 2016  路  11Comments  路  Source: docker/compose

The services defined in docker-compose.yml allow hyphens in their name, which means that the resulting containers can obtain the following names:

myproject_some-other-service_1

However, when it is attempted to use COMPOSE_PROJECT_NAME=my-project instead of myproject, the names of the services do not change to the following:

my-project_some-other-service_1

The cause is this line in command.py:

 return re.sub(r'[^a-z0-9]', '', name.lower())

I might be wrong, but there seems to be no reason for having inconsistent naming restrictions in different parts of the resulting container name. Could be go for this?

 return re.sub(r'[^a-z0-9-]', '', name.lower())

Some of my projects haveprettylongnamesanditbecomeshardtoreadthemwithouthyphens. this-could-be-improved.

Most helpful comment

This is actually a HUGE breaking change 馃槺
I think you should revert it in 1.21.2 and rerelease as 1.22 or even 2.0.0 (if you follow semver).

All 11 comments

Exactly the same problem applies to underscores at the moment:

#possible
myproject_some_service_1
myproject_some_other_service_1

#not possible
my_project_some_service_1
my_project_some_other_service_1

Although I'm a supporter of using hyphens and underscores for their own distnict purposes, I still don't see why different rules should be applied to different parts of the name. A complete fix would look like this:

 return re.sub(r'[^a-z0-9_-]', '', name.lower())

@aanand Do you remember if there was a specific reason for stripping out those characters in project names?

There is closed PR #572 for this. But since a project is tracked via label this reason is out.

Could a little patch that resolves this issue be included in the next minor release then please?

This is super annoying as a distributor.

What if the user already has a "lamp_1" container?? I try to prefix it with my project name and it comes out "phpexpertslamp_1", which is far from ideal.

Yet there's no recourse ATM, going on a year and half.

Fixed by #5788

I, like many others (I assume), had named volumes they were using with Docker Compose and now those volumes don't have the correct name (e.g. it used to be myapp_database and is now built by Compose as my-app_database). I tried going through a lengthy process of renaming the volume using this script and this forum post to figure out how to move my data from one volume to another. Somehow running the mv command to move the data directories resulted in a complete loss of all of my volume's data and I don't know why.

Is there an official recommended means of renaming volumes? This seems like something that should be relatively straightforward to accomplish, but the last hour and a half of my searching and testing shows that's not the case.

@ajmueller I can't speak to third party scripts, but the upcoming 1.21.1 should handle the migration correctly. See #5874 for more information

Thanks, @shin-. It looks like docker cp would have been an option then.

If anyone happens across this and needs another option, this utility might do the trick. DISCLAIMER I didn't try it personally, but it looks like it should do the trick.

This is actually a HUGE breaking change 馃槺
I think you should revert it in 1.21.2 and rerelease as 1.22 or even 2.0.0 (if you follow semver).

Any build system or script that makes the assumption that an underscore is the delimiter between projectname, and container will be broken by this change.

Was this page helpful?
0 / 5 - 0 ratings