-
Notifications
You must be signed in to change notification settings - Fork 25
Conversation
…ry'. This change modifies the container name creation to be in conformity with original Docker Compose. So, container names are now generated following the pattern below: [compose directory]_[container identifier]_[sequential ID], where: - [compose directory]: the directory where compose is being executed; - [container identifier]: the container given name (or label, if name isn't provided); - [sequential ID]: the next ID available for container naming (defaults to '1' if no container's running); It was also added a new method to fetch containers by its given name. So: # Query containers by its full name compose.get_containers_by(name: 'myawessomedir_servicefoo_1') # Query containers by its given name, ignoring both prefix and suffix compose.get_containers_by_given_name('servicefoo')
Now, the containers are started with a name that inform its origin (it means, the compose file that started it). So, a new compose instance is now able to recognize such containers and load them into its context. Instructions to load the previous started containers can be found on README file.
Would love to see this merged. |
# | ||
def get_containers_by_given_name(given_name) | ||
@containers.select { |label, container| | ||
container.attributes[:name].match(/\w*_#{given_name}_\d+/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say it would be safer if @dir_name
from ComposeUtils
could be used there instead of \w+
, no? While the chance is small it is still there that another container could coincidentally use the same naming convention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right!
I've fixed it to filter containers based on its directory name as well.
Thanks for the suggestion!
Looks good! 👍 Fyi: docker-compose is using labels instead of names to identify containers now (since v1.3.0 I think): docker/compose#1356. |
A bit hackish, but in my project I'm setting a bunch of custom labels which I use to identify containers: https://github.com/playpasshq/docker-compose-api/commit/7ca4a2ebad95a2224332dee9fd6b4f01f4f335f7. (setting the labels happens on a higher level right now) |
Indeed compose is now using label instead names to recognized containers started previously. Let me know if you guys share the same thoughts. |
…s name on compose memory.
@mauricioklein I agree. As it is now (including this feature) it does what I expect and does everything I need for the project I am using it for. At some point it might be nice that it does exaclty the same as compose itself, but I think it would involve quite some work. You already did a good job on the gem right now! 👍 |
…memory Feature: compose 'memory'
This PR provides the ability to compose recognize containers started by it previously and reload them in a different context.
This is done analyzing the containers name, searching for those who has the same pattern of current compose.
This feature is optional and must be enabled explicitly on compose load method (instructions provided on README file).