1

I am trying to reuse existing cookbooks within docker containers, but most recipes will start the service during the chef client run (e.g. tomcat, apache2). As chef-solo runs during image creation the chef run will simply fail.

How can I prevent a cookbook from starting a service?

I am using the following Dockerfile

FROM jr42/chef-solo-centos

ADD chef /chef
RUN cd /chef && /opt/chef/embedded/bin/berks vendor /chef/cookbooks
RUN chef-solo -N mynode -c /chef/solo.rb -j /chef/solo.json

tomcat in my runbook (solo.json):

{
  "tomcat": {
    "base_version": ""
  },
  "run_list": [ "recipe[tomcat]" ]
}

and Berksfile:

source "https://supermarket.getchef.com"
metadata
cookbook 'tomcat'
0

It appears that you are using the cookbook with unmodified attributes, and the default behavior of the tomcat cookbook is to run a 'default' base tomcat instance.

Refer to the resource declared here and the attribute setting here.

You should be able to update your solo.json to override this attribute:

{
  "tomcat": {
    "base_version": "",
    "run_base_instance": false
  },
  "run_list": [ "recipe[tomcat]" ]
}

And you shouldn't have the service automatically start.

Alternately, you could look at the chef-container project documentation and see if this maps to a better build procedure for your containerized application.

|improve this answer|||||
  • Thanks for the answer. It solves the issue with the tomcat cookbook. Is there no general way to prevent service start, stops and restarts? I have similar issues with almost every cookbook during "docker build". This includes chef-container – jr42 Oct 6 '14 at 9:25
  • @jr42 Many cookbook maintainers assume that the desired state of a recipe is that a service be started when the "thing" is configured - not exactly docker-friendly. You could try looking at something like chef-rewind's unwind to remove particular resources - but this is a tricky thing to get right. – Mike Fiedler Oct 6 '14 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.