lib/chef/provisioning/docker_driver/docker_container_machine.rb
# Create the final container from the converged image
Create the final container from the converged image
Create the final container from the converged image
def create_container(action_handler, machine_spec, converged_image)
      container = container_for(machine_spec)
      if container
        if container.info['Image'] == converged_image.id
          return container
        else
          action_handler.perform_action "stop and delete running container for #{machine_spec.name}" do
            container.stop!
            container.delete
          end
        end
      end
      config = container_config(action_handler, machine_spec)
      config.merge!(
        'name' => machine_spec.reference['container_name'],
        'Image' => converged_image.id
      )
      action_handler.perform_action "create final container for #{machine_spec.name}" do
        container = Docker::Container.create(config, @connection)
        machine_spec.reference['container_id'] = container.id
        machine_spec.save(action_handler)
      end
      container
    end
def create_container ( action_handler , machine_spec , converged_image ) container = container_for ( machine_spec ) if container if container . info [ 'Image' ] == converged_image . id return container else action_handler . perform_action "stop and delete running container for #{machine_spec.name}" do container . stop! container . delete end end end config = container_config ( action_handler , machine_spec ) config . merge! ( 'name' => machine_spec . reference [ 'container_name' ] , 'Image' => converged_image . id ) action_handler . perform_action "create final container for #{machine_spec.name}" do container = Docker :: Container . create ( config , @connection ) machine_spec . reference [ 'container_id' ] = container . id machine_spec . save ( action_handler ) end container end
Create the final container from the converged image
Create the final container from the converged image
# Check if the container already exists. # If it's the same image, just return; don't stop and start. # If the container exists but is based on an old image, destroy it. # Create the new container
action_handler
<not_specific>
machine_spec
<not_specific>
converged_image
<not_specific>