Fix incorrect loading of container name when links are present. #204
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bug summary
The docker_container provider will incorrectly attempt to recreate the docker container if the container already exists and has other containers linking to it.
How to reproduce
docker run --name='my-db'
)docker run --name my-app --link my-db:db
)docker ps
)Here are my containers as listed in
docker ps
:The reason this happens is because the docker_container provider uses the raw name (as listed in docker ps) as default value for
@current_resource.container_name
; in my example, this means that the providers loadsmy-app,my-db/db
as the container_name instead ofmy-db
; since the provider (incorrectly) filled the container_name attribute then it will wrongly think that the container does not exist and attempt to create it with therun action
; thendocker run
will fail with the above message because the container namedmy-db
already exists.Suggested fix
This simple PR should fix the problem by trying to guess which is the
main
container name from rawdocker ps
output. I considered that every names which contain a'/'
character are link names and should be ignored, this works fine enough for me.