<commit_before>require 'docker'

module Ganger
  class DockerServer
    
    def initialize(docker_url)
      @docker_url = docker_url
      @connection = Docker::Connection.new(docker_url, {})
      @containers = []
      @image_pulled = false
    end
    
    def launch_container
      pull_image unless @image_pulled
      container_opts = {
        'Image' => Ganger.configuration.docker_image,
        'ExposedPorts' => { Ganger.configuration.docker_expose => {} }
      }
      container_opts['Cmd'] = Ganger.configuration.docker_cmd if Ganger.configuration.docker_cmd

      container = Docker::Container.create(container_opts, @connection)
      container.start({
        "PortBindings" => { 
          Ganger.configuration.docker_expose => [{"HostPort" => ""}]
        }
      })
      internal_container = DockerContainer.new(container, @docker_url)
      @containers << internal_container
      internal_container
    end
    
    def kill_containers
      @containers.each do |container|
        container.dispose
      end
    end
    
    def container_count
      @containers.size
    end
    
    def pull_image
      Docker::Image.create({'fromImage' => Ganger.configuration.docker_image}, @connection)
      @image_pulled = true
    end
    
  end
end<commit_msg>Fix subtle bug with sending connection image creation<commit_after>require 'docker'

module Ganger
  class DockerServer
    
    def initialize(docker_url)
      @docker_url = docker_url
      @connection = Docker::Connection.new(docker_url, {})
      @containers = []
      @image_pulled = false
    end
    
    def launch_container
      pull_image unless @image_pulled
      container_opts = {
        'Image' => Ganger.configuration.docker_image,
        'ExposedPorts' => { Ganger.configuration.docker_expose => {} }
      }
      container_opts['Cmd'] = Ganger.configuration.docker_cmd if Ganger.configuration.docker_cmd

      container = Docker::Container.create(container_opts, @connection)
      container.start({
        "PortBindings" => { 
          Ganger.configuration.docker_expose => [{"HostPort" => ""}]
        }
      })
      internal_container = DockerContainer.new(container, @docker_url)
      @containers << internal_container
      internal_container
    end
    
    def kill_containers
      @containers.each do |container|
        container.dispose
      end
    end
    
    def container_count
      @containers.size
    end
    
    def pull_image
      Docker::Image.create({'fromImage' => Ganger.configuration.docker_image}, nil, @connection)
      @image_pulled = true
    end
    
  end
end
{'fraction_non_alphanumeric': 0.09467228823303948, 'fraction_numerical': 0.0, 'mean_word_length': 2.6401673640167362, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6689809', 'n_tokens_mistral': 778, 'n_tokens_neox': 745, 'n_words': 139}