0
votes

Below is my recipe for docker. I have installed docker using chef and its installed properly but when i am trying to pull the image through chef its not working:

# default.rb

package 'docker' do
  action :install
end

service 'default' do
  action [ :enable, :start ]
end

docker_image 'nginx' do
  tag 'latest'
  action :pull
end

I am getting below error when running chef client locally and testing:

NoMethodError undefined method `docker_image' for cookbook: docker, recipe: default :Chef::Recipe

As I am new to chef so need help on above issue

1

1 Answers

0
votes

docker_image resource is not defined in chef core, so you must provide the source of definition. This resource is defined in docker cookbook, which is available in supermarket. So you must depend on that cookbook to use the resource. Add a line into metadata.rb of your cookbook:

# metadata.rb

depends 'docker', '~> 6.0'

Then your dependency management engine (Berkshelf, Policyfile) will be able to find and download the cookbook.