Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect loading of container name when links are present. #204

Conversation

jperville
Copy link
Contributor

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

  1. declare a docker_container resource (with docker run --name='my-db')
  2. declare another docker_container resource that link to the first one (eg. docker run --name my-app --link my-db:db)
  3. run chef-client, it passes (and the link can be seen in output of docker ps)
  4. run chef-client again, docker will fail with the following message:
Error response from daemon: Conflict, The name my-db is already assigned to d0ac4cf80ab1. You have to delete (or rename) that container to be able to assign my-db to a container again.

Here are my containers as listed in docker ps:

a6ebcb14df56        registry.local/my-db:latest   "/sbin/my_init --ena   44 minutes ago      Up 44 minutes       1337/tcp     my-db                   
d0ac4cf80ab1        registry.local/my-app:latest   "/sbin/my_init --ena   45 minutes ago      Up 45 minutes       80/tcp     my-app,my-db/db   

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 loads my-app,my-db/db as the container_name instead of my-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 the run action ; then docker run will fail with the above message because the container named my-db already exists.

Suggested fix

This simple PR should fix the problem by trying to guess which is the main container name from raw docker ps output. I considered that every names which contain a '/' character are link names and should be ignored, this works fine enough for me.

@jperville
Copy link
Contributor Author

After further investigation, the problem is not specific to links, it just happens to show up when links are used. The actual problem is that the container_matches? method in the container provider is to lax and will accidentally match the wrong container, thus breaking my links further in my test suite.

I close this PR and will open a new one shortly (referencing this PR).

@jperville jperville closed this Aug 29, 2014
@jperville jperville deleted the fix-container-name-detection-with-links branch August 29, 2014 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant