lib/chef/provisioning/docker_driver/docker_container_machine.rb
# Builds a container that has the same properties as the final container,
# but with a couple of tweaks to allow processes to run and converge the
# container.
Builds a container that has the same properties as the final container,
but with a couple of tweaks to allow processes to run and converge the
container.
Builds a container that has the same properties as the final container but with a couple of tweaks to allow processes to run and converge the container .
def build_converge_container(action_handler)
      converge_container = converge_container_for(machine_spec)
      if converge_container
        return converge_container
      end
      config = container_config(action_handler, machine_spec)
      config.merge!(
        'name' => "chef-converge.#{machine_spec.reference['container_name']}",
        'Cmd' => [ "/bin/sh", "-c", "while true;do sleep 1000; done" ],
      )
      if transport.is_local_machine(URI(transport.config[:chef_server_url]).host) &&
         transport.docker_toolkit_transport(@connection.url)
        config['HostConfig'] ||= {}
        config['HostConfig'].merge!('NetworkMode' => 'host')
        config['HostConfig'].delete('Links')
        config['HostConfig'].delete('ExtraHosts')
        config.delete('NetworkSettings')
      end
      config.delete('ExposedPorts')
      Chef::Log.debug("Creating converge container with config #{config} ...")
      action_handler.perform_action "create container to converge #{machine_spec.name}" do
        Docker::Container.create(config.dup, @connection)
        converge_container = Docker::Container.get(config['name'], {}, @connection)
        Chef::Log.debug("Created converge container #{converge_container.id}")
      end
      converge_container
    end
def build_converge_container ( action_handler ) converge_container = converge_container_for ( machine_spec ) if converge_container return converge_container end config = container_config ( action_handler , machine_spec ) config . merge! ( 'name' => "chef-converge.#{machine_spec.reference['container_name']}" , 'Cmd' => [ "/bin/sh" , "-c" , "while true;do sleep 1000; done" ] , ) if transport . is_local_machine ( URI ( transport . config [ :chef_server_url ] ) . host ) && transport . docker_toolkit_transport ( @connection . url ) config [ 'HostConfig' ] ||= { } config [ 'HostConfig' ] . merge! ( 'NetworkMode' => 'host' ) config [ 'HostConfig' ] . delete ( 'Links' ) config [ 'HostConfig' ] . delete ( 'ExtraHosts' ) config . delete ( 'NetworkSettings' ) end config . delete ( 'ExposedPorts' ) Chef :: Log . debug ( "Creating converge container with config #{config} ..." ) action_handler . perform_action "create container to converge #{machine_spec.name}" do Docker :: Container . create ( config . dup , @connection ) converge_container = Docker :: Container . get ( config [ 'name' ] , { } , @connection ) Chef :: Log . debug ( "Created converge container #{converge_container.id}" ) end converge_container end
Builds a container that has the same properties as the final container,
but with a couple of tweaks to allow processes to run and converge the
container.
Builds a container that has the same properties as the final container but with a couple of tweaks to allow processes to run and converge the container .
# If a converge container already exists, do nothing. TODO check if it's different!!! # Create a chef-capable container (just like the final one, but with --net=host # and a command that keeps it open). Base it on the image. # If we're using Docker Toolkit, we need to use host networking for the converge # so we can open up the port we need. Don't force it in other cases, though. # These are incompatible with NetworkMode: host # Don't use any resources that need to be shared (such as exposed ports) # create deletes the name :(
action_handler
<not_specific>