[chef] Docker_container dependency hell


Chronological Thread 
  • From: Kevin Keane Subscription < >
  • To: < >
  • Subject: [chef] Docker_container dependency hell
  • Date: Sun, 6 Sep 2015 15:10:52 -0700

Title: Docker_container dependency hell

I have two docker containers. Container 1 links to container 2 (target). Consequently, container2 needs to be created and started before container1.

What I am trying to accomplish is this:

- if the containers do not exist, they will be run in the correct sequence, even if the images already exist.

- If an image for container1 is updated, container 1 is redeployed.

- If an image for container2 is updated, containers2 is redeployed, and then container1 is redeployed.


Here is what I am currently doing (simplified for readability)

docker_image image1 do

   action :nothing

   # built only based on notifications

end

docker_container container2 do

  action :run_if_missing

  subscribe :redeploy, "docker_image[image2]"

end

And in another cookbook:

docker_image image2 do

  action :nothing

  # built only based on notifications

end

docker_container container1 do

  action :run_if_missing

  subscribe :redeploy, "docker_image[image1]

  subscribe :redeploy, "docker_container[container2]

end


Problems with this approach:

- The containers are often built twice, first by the run_if_missing action, and then again by the redeploy action

- The run_if_missing action does not observe dependencies, so container1's run_if_missing action is actually invoked before container2 even exists, causing a build failure.

Obviously, I could circumvent this by changing the default action to :nothing, but then the containers aren't built at all if they are missing.

Also, using :immediate for the subscriptions is not an option (because then the redeploy action may get invoked too early and multiple times, and various other problems).

What is the best way to resolve this?


Kevin Keane

The NetTech

http://www.4nettech.com

Our values: Privacy, Liberty, Justice

See https://www.4nettech.com/corp/the-nettech-values.html





Archive powered by MHonArc 2.6.16.

§