Full Lifetime
Full Lifetime

Reputation: 31

How to solve the error undefined method `docker_image' for cookbook in chef-client process

I am trying to bootstrap a new server. I get an error with the docker_image resource when I run the knife bootstrap command on my server. Please see this more detailed logs. Thank you.

Synchronizing cookbooks:
  - logrotate (2.2.2)
  - chrony-ntp (1.2.0)
  - docker (4.9.3)
  - cmlabs-docker-postgres (0.3.0)

...

NoMethodError
-------------
undefined method `docker_image' for cookbook: cmlabs-docker-postgres, recipe: default :Chef::Recipe
...

Relevant File Content:

/var/chef/cache/cookbooks/cmlabs-docker-postgres/recipes/default.rb:

 12:  service_collation = node['cmlabs-docker-postgres']['service_collation']
 13:  service_maxconn = node['cmlabs-docker-postgres']['max_connections']
 14:
 15:  docker_service 'default' do
 16:    action [:create, :start]
 17:  end
 18:
 19>> docker_image 'postgres' do
 20:    tag node['cmlabs-docker-postgres']['tag']
 21:    action :pull
 22:  end
 23:
 24:  docker_network node['cmlabs-docker-postgres']['network'] do
 25:    action :create
 26:  end
 27:
 28:  docker_container 'postgres' do

System Info:

chef_version=17.9.42
platform=centos
platform_version=7.9.2009
ruby=ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x86_64-linux]
program_name=/usr/bin/chef-client
executable=/opt/chef/bin/chef-client

Upvotes: 3

Views: 642

Answers (1)

seshadri_c
seshadri_c

Reputation: 7340

Version 4.9.3 of the docker cookbook seems to be quite old. Current version is 10.1.6. Unless you have a specific reason to use this specific version, I'd suggest using a higher version as a dependency in your cookbook.

I tried with version 8.3.0, and it seems to work fine. Example:

metadata.rb:

depends 'docker', '>= 8.3.0'

recipes/default.rb:

docker_image 'busybox' do
  action :pull
end

Works as expected:

Synchronizing Cookbooks:
  - cookbook1 (0.1.0)
  - docker (8.3.0)
...
...
Converging 1 resources
Recipe: cookbook1::default
  * docker_image[busybox] action pull
    - Pull image busybox:latest

Upvotes: 1

Related Questions