public static DockerContainer fromContainerInfo(ContainerInfo container) {
   Map<String, String> labels = container.config().labels();
   return new DockerContainer(
       container.name().substring(1),
       container.created(),
       GSON.fromJson(labels.get(Constants.CONFIGURATION_LABEL_KEY), HashMap.class),
       labels.get(Constants.ENVIRONMENT_LABEL_KEY));
 }
  public static DockerContainer create(
      CreateAgentRequest request, PluginSettings settings, DockerClient docker)
      throws InterruptedException, DockerException, IOException {
    String containerName = UUID.randomUUID().toString();

    HashMap<String, String> labels = labelsFrom(request);
    String imageName = image(request.properties());
    List<String> env = environmentFrom(request, settings, containerName);

    try {
      docker.inspectImage(imageName);
    } catch (ImageNotFoundException ex) {
      LOG.info("Image " + imageName + " not found, attempting to download.");
      docker.pull(imageName);
    }

    ContainerConfig.Builder containerConfigBuilder = ContainerConfig.builder();
    if (request.properties().containsKey("Command")) {
      containerConfigBuilder.cmd(
          splitIntoLinesAndTrimSpaces(request.properties().get("Command"))
              .toArray(new String[] {}));
    }

    ContainerConfig containerConfig =
        containerConfigBuilder.image(imageName).labels(labels).env(env).build();
    ContainerCreation container = docker.createContainer(containerConfig, containerName);
    String id = container.id();

    ContainerInfo containerInfo = docker.inspectContainer(id);

    LOG.debug("Created container " + containerName);
    docker.startContainer(containerName);

    return new DockerContainer(
        containerName, containerInfo.created(), request.properties(), request.environment());
  }