Code review comment: Indeed looks like a rebasing error. A bit tricky one to get right because we changed the way the container removal worked before the rebasing was done. We were using the `--rm` initially but before the rebase we changed it to remove the container explicitly via `docker remove <container_id>`.

Code under review:
public RemoteEnvironment createEnvironment(Environment environment) throws Exception {
    Preconditions.checkState(
        environment
            .getUrn()
            .equals(BeamUrns.getUrn(RunnerApi.StandardEnvironments.Environments.DOCKER)),
        "The passed environment does not contain a DockerPayload.");
    final RunnerApi.DockerPayload dockerPayload =
        RunnerApi.DockerPayload.parseFrom(environment.getPayload());
    final String workerId = idGenerator.getId();

    
    String containerImage = dockerPayload.getContainerImage();
    
    
    String loggingEndpoint = loggingServiceServer.getApiServiceDescriptor().getUrl();
    String artifactEndpoint = retrievalServiceServer.getApiServiceDescriptor().getUrl();
    String provisionEndpoint = provisioningServiceServer.getApiServiceDescriptor().getUrl();
    String controlEndpoint = controlServiceServer.getApiServiceDescriptor().getUrl();

    ImmutableList.Builder<String> dockerOptsBuilder =
        ImmutableList.<String>builder()
            .addAll(gcsCredentialArgs())
            
            .add("--network=host")
            
            
            .add("--env=DOCKER_MAC_CONTAINER=" + System.getenv("DOCKER_MAC_CONTAINER"));

    Boolean retainDockerContainer =
        pipelineOptions.as(ManualDockerEnvironmentOptions.class).getRetainDockerContainers();
    if (!retainDockerContainer) {
      dockerOptsBuilder.add("--rm");
    }

    String semiPersistDir = pipelineOptions.as(RemoteEnvironmentOptions.class).getSemiPersistDir();
    ImmutableList.Builder<String> argsBuilder =
        ImmutableList.<String>builder()
            .add(String.format("--id=%s", workerId))
            .add(String.format("--logging_endpoint=%s", loggingEndpoint))
            .add(String.format("--artifact_endpoint=%s", artifactEndpoint))
            .add(String.format("--provision_endpoint=%s", provisionEndpoint))
            .add(String.format("--control_endpoint=%s", controlEndpoint));
    if (semiPersistDir != null) {
      argsBuilder.add(String.format("--semi_persist_dir=%s", semiPersistDir));
    }

    LOG.debug("Creating Docker Container with ID {}", workerId);
    
    String containerId = null;
    InstructionRequestHandler instructionHandler = null;
    try {
      containerId = docker.runImage(containerImage, dockerOptsBuilder.build(), argsBuilder.build());
      LOG.debug("Created Docker Container with Container ID {}", containerId);
      
      try {
        instructionHandler = clientSource.take(workerId, Duration.ofMinutes(1));
      } catch (TimeoutException timeoutEx) {
        RuntimeException runtimeException =
            new RuntimeException(
                String.format(
                    "Docker container %s failed to start up successfully within 1 minute.",
                    containerImage),
                timeoutEx);
        try {
          String containerLogs = docker.getContainerLogs(containerId);
          LOG.error("Docker container {} logs:\n{}", containerId, containerLogs);
        } catch (Exception getLogsException) {
          runtimeException.addSuppressed(getLogsException);
        }
        throw runtimeException;
      } catch (InterruptedException interruptEx) {
        Thread.currentThread().interrupt();
        throw new RuntimeException(interruptEx);
      }
    } catch (Exception e) {
      if (containerId != null) {
        
        try {
          docker.killContainer(containerId);
          if (!retainDockerContainer) {
            docker.removeContainer(containerId);
          }
        } catch (Exception dockerException) {
          e.addSuppressed(dockerException);
        }
      }
      throw e;
    }

    return DockerContainerEnvironment.create(
        docker, environment, containerId, instructionHandler, retainDockerContainer);
  }

Line commented on: dockerOptsBuilder.add("--rm");

Revised code:
public RemoteEnvironment createEnvironment(Environment environment) throws Exception {
    Preconditions.checkState(
        environment
            .getUrn()
            .equals(BeamUrns.getUrn(RunnerApi.StandardEnvironments.Environments.DOCKER)),
        "The passed environment does not contain a DockerPayload.");
    final RunnerApi.DockerPayload dockerPayload =
        RunnerApi.DockerPayload.parseFrom(environment.getPayload());
    final String workerId = idGenerator.getId();

    
    String containerImage = dockerPayload.getContainerImage();
    
    
    String loggingEndpoint = loggingServiceServer.getApiServiceDescriptor().getUrl();
    String artifactEndpoint = retrievalServiceServer.getApiServiceDescriptor().getUrl();
    String provisionEndpoint = provisioningServiceServer.getApiServiceDescriptor().getUrl();
    String controlEndpoint = controlServiceServer.getApiServiceDescriptor().getUrl();

    ImmutableList.Builder<String> dockerOptsBuilder =
        ImmutableList.<String>builder()
            .addAll(gcsCredentialArgs())
            
            .add("--network=host")
            
            
            .add("--env=DOCKER_MAC_CONTAINER=" + System.getenv("DOCKER_MAC_CONTAINER"));

    Boolean retainDockerContainer =
        pipelineOptions.as(ManualDockerEnvironmentOptions.class).getRetainDockerContainers();
    if (!retainDockerContainer) {
      dockerOptsBuilder.add("--rm");
    }

    String semiPersistDir = pipelineOptions.as(RemoteEnvironmentOptions.class).getSemiPersistDir();
    ImmutableList.Builder<String> argsBuilder =
        ImmutableList.<String>builder()
            .add(String.format("--id=%s", workerId))
            .add(String.format("--logging_endpoint=%s", loggingEndpoint))
            .add(String.format("--artifact_endpoint=%s", artifactEndpoint))
            .add(String.format("--provision_endpoint=%s", provisionEndpoint))
            .add(String.format("--control_endpoint=%s", controlEndpoint));
    if (semiPersistDir != null) {
      argsBuilder.add(String.format("--semi_persist_dir=%s", semiPersistDir));
    }

    LOG.debug("Creating Docker Container with ID {}", workerId);
    
    String containerId = null;
    InstructionRequestHandler instructionHandler = null;
    try {
      containerId = docker.runImage(containerImage, dockerOptsBuilder.build(), argsBuilder.build());
      LOG.debug("Created Docker Container with Container ID {}", containerId);
      
      try {
        instructionHandler = clientSource.take(workerId, Duration.ofMinutes(1));
      } catch (TimeoutException timeoutEx) {
        RuntimeException runtimeException =
            new RuntimeException(
                String.format(
                    "Docker container %s failed to start up successfully within 1 minute.",
                    containerImage),
                timeoutEx);
        try {
          String containerLogs = docker.getContainerLogs(containerId);
          LOG.error("Docker container {} logs:\n{}", containerId, containerLogs);
        } catch (Exception getLogsException) {
          runtimeException.addSuppressed(getLogsException);
        }
        throw runtimeException;
      } catch (InterruptedException interruptEx) {
        Thread.currentThread().interrupt();
        throw new RuntimeException(interruptEx);
      }
    } catch (Exception e) {
      if (containerId != null) {
        
        try {
          docker.killContainer(containerId);
          if (!retainDockerContainer) {
            docker.removeContainer(containerId);
          }
        } catch (Exception dockerException) {
          e.addSuppressed(dockerException);
        }
      }
      throw e;
    }

    return DockerContainerEnvironment.create(
        docker, environment, containerId, instructionHandler, retainDockerContainer);
  }