chef-provisioning-docker icon indicating copy to clipboard operation
chef-provisioning-docker copied to clipboard

provisioning docker with chef-provisioning fails with "no such id"

Open abdulrahman86 opened this issue 9 years ago • 2 comments

0 down vote favorite I am trying to provision my docker image using chef. I run the following.

knife cookbook site install apt -z
knife cookbook site install haproxy -z
knife cookbook site install tomcat -z
knife cookbook site install postgresql -z
export CHEF_DRIVER=docker
chef-client -z ~/deploy-environment.rb

My deploy-environment.rb file looks as follows

# Deploy a database server, two app servers, and a load balancer
require 'chef/provisioning/docker_driver'

# global variables
chef_env = '_default'
domain = 'myapp.local'
subdomain = "#{chef_env}.#{domain}"

# Dev/Non-Prod instance count
num_appservers = 2
num_dbservers = 1

# Conditional deployment
if chef_env.eql?("production")
  num_appservers = 3
  num_dbservers = 2
end

# DB server(s)
# Standby DB could be configured as such after finding online Active node
# One method would be to add to a recipe search(:node, 'recipes:"postgresql::server"')
1.upto(num_dbservers) do |i|
  machine "db#{i}.#{domain}" do
    recipe 'apt::default' # Update local apt database
    recipe 'postgresql::server'
    chef_environment chef_env
      machine_options :docker_options => {
        :base_image => {
          :name => 'ubuntu',
          :repository => 'ubuntu',
          :tag => '14.04'
        },
        :command => 'service postgresql start'
      }
  end
end

# Launch Application servers in parallel
machine_batch do
  1.upto(num_appservers) do |i|
    machine "app#{i}.#{domain}" do
      recipe 'apt::default' # Update local apt database
      recipe 'tomcat'
      chef_environment chef_env
      attribute 'tomcat', { 'base_version' => 7 } # sets node['tomcat']['base_version']
      attribute 'java', { 'java_home' => '/usr/lib/jvm/java-1.7.0-openjdk-amd64' } # sets node['java']['java_home']
      machine_options :docker_options => {
        :base_image => {
        :name => 'ubuntu',
        :repository => 'ubuntu',
        :tag => '14.04'
        },
        :command => 'service tomcat7 start'
      }
    end
  end
end

# Load balancer
machine "lb1.#{domain}" do
  recipe 'haproxy'
  chef_environment chef_env
  machine_options :docker_options => {
      :base_image => {
      :name => 'ubuntu',
      :repository => 'ubuntu',
      :tag => '14.04'
    },
    :command => 'service haproxy start'
  }
end

However I get this when I run chef-client

ERROR: machine[wario] (@recipe_files::/Users/asattar/Dev/projects/chef-repo/deploy-environment-4.rb line 3) had an error: Docker::Error::NotFoundError: no such id: a3ed95caeb02

abdulrahman86 avatar Feb 20 '16 20:02 abdulrahman86

I get the same error with Docker containers inside upto *loop

aslheyrr avatar Feb 22 '16 14:02 aslheyrr

hey @rizotas what do you mean upto cicle?

abdulrahman86 avatar Feb 22 '16 14:02 abdulrahman86