com.spotify.docker.client.DockerRequestException: Request error: DELETE unix://localhost:80/v1.12/containers/…: 409

I am working on a Java application which deploys web artifacts in Apache Tomcat Docker Containers with the use of Google Kubernetes. I am using in order to carry out Docker Image and Container handling activities and for Kubernetes related functionalities.

In this application, I have added a functionality which enables the user to remove a web artifact which the user deploys.

  • Build Docker image only if Code Repository has been updated (Jenkins)
  • Docker Compose Mount Window Folder
  • Assign network aliases dynamically on global deployed services in a docker stack
  • Which OS for docker [closed]
  • Docker - var/lib/docker/layers folder content
  • docker stop spark container from exiting
  • When removing I,

    1. delete the Kubernetes replication controller which I use to generate the desired number of pod replicas

    2. separately delete off the replica pods (as pods are not deleted automatically when the replication controller is deleted in the corresponding method in the Java API)

    3. delete off the corresponding Service created

    4. delete off the Docker Containers corresponding to the pods deleted off

    5. finally, remove the Docker Image used for the deployment

    Following code shows the removal functionality implemented:

    public boolean remove(String tenant, String appName) throws WebArtifactHandlerException {
            String componentName = generateKubernetesComponentName(tenant, appName);
            final int singleImageIndex = 0;
            try {
                if (replicationControllerHandler.getReplicationController(componentName) != null) {
                    String dockerImage = replicationControllerHandler.getReplicationController(componentName).getSpec()
                    List<String> containerIds = containerHandler.getRunningContainerIdsByImage(dockerImage);
                    podHandler.deleteReplicaPods(tenant, appName);
                    imageBuilder.removeImage(tenant, appName, getDockerImageVersion(dockerImage));
                    return true;
                } else {
                    return false;
            } catch (Exception exception) {
                String message = String.format("Failed to remove web artifact[artifact]: %s",
                        generateKubernetesComponentName(tenant, appName));
                LOG.error(message, exception);
                throw new WebArtifactHandlerException(message, exception);

    Implementation of the Docker Container deletion functionality is as follows:

    public void deleteContainers(List<String> containerIds) throws WebArtifactHandlerException {
            try {
                for (String containerId : containerIds) {
            } catch (Exception exception) {
                String message = "Could not delete the Docker Containers.";
                LOG.error(message, exception);
                throw new WebArtifactHandlerException(message, exception);

    In the above case although the execution of the desired function takes place without any sort of issue, at certain instances I tend to get the following exception.

    Sep 11, 2015 3:57:28 PM org.apache.poc.webartifact.WebArtifactHandler remove
    SEVERE: Failed to remove web artifact[artifact]: app-wso2-com
    org.apache.poc.miscellaneous.exceptions.WebArtifactHandlerException: Could not delete the Docker Containers.
        at org.apache.poc.docker.JavaWebArtifactContainerHandler.deleteContainers(
        at org.apache.poc.webartifact.WebArtifactHandler.remove(
        at org.apache.poc.Executor.process(
        at org.apache.poc.Executor.main(
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(
        at java.lang.reflect.Method.invoke(
        at com.intellij.rt.execution.application.AppMain.main(
    Caused by: com.spotify.docker.client.DockerRequestException: Request error: DELETE unix://localhost:80/v1.12/containers/af05916d2bddf73dcf8bf41c6ea7f5f3b859c90b97447a8248ffa7b5b3968691: 409
        at com.spotify.docker.client.DefaultDockerClient.propagate(
        at com.spotify.docker.client.DefaultDockerClient.request(
        at com.spotify.docker.client.DefaultDockerClient.removeContainer(
        at com.spotify.docker.client.DefaultDockerClient.removeContainer(
        at org.wso2.carbon6.poc.docker.JavaWebArtifactContainerHandler.deleteContainers(
        ... 8 more
    Caused by: HTTP 409 Conflict
        at org.glassfish.jersey.client.JerseyInvocation.createExceptionForFamily(
        at org.glassfish.jersey.client.JerseyInvocation.convertToException(
        at org.glassfish.jersey.client.JerseyInvocation.translate(
        at org.glassfish.jersey.client.JerseyInvocation.access$500(
        at org.glassfish.jersey.client.JerseyInvocation$5.completed(
        at org.glassfish.jersey.client.ClientRuntime.processResponse(
        at org.glassfish.jersey.client.ClientRuntime.access$300(
        at org.glassfish.jersey.client.ClientRuntime$
        at org.glassfish.jersey.internal.Errors$
        at org.glassfish.jersey.internal.Errors$
        at org.glassfish.jersey.internal.Errors.process(
        at org.glassfish.jersey.internal.Errors.process(
        at org.glassfish.jersey.internal.Errors.process(
        at org.glassfish.jersey.process.internal.RequestScope.runInScope(
        at org.glassfish.jersey.client.ClientRuntime$
        at java.util.concurrent.Executors$
        at java.util.concurrent.ThreadPoolExecutor.runWorker(
        at java.util.concurrent.ThreadPoolExecutor$

    I searched a large number of sources for any help for this but still I wasn’t able to avoid it in all instances, I execute this functionality.

    At the beginning I tended to get this issue more often than now, but allowing the executing thread to sleep at the end of deleting each Docker Container and before deleting any Docker Containers, gradually reduced the number of instances I am getting this issue.

    Is sleeping the thread the ultimate solution for this issue or is there any other reason for this issue to pop and a solution that can help me to avoid this exception? Any help is greatly appreciated.

  • How to enable gerrit hooks?
  • Docker-swarm error: read-only file system
  • Auto-synch data in container upon changes in host
  • Spark clustering with yarn
  • XDebug: Windows + Docker + PHPStorm
  • How can I reproduce zombie process with bash as PID1 in docker?
  • One Solution collect form web for “com.spotify.docker.client.DockerRequestException: Request error: DELETE unix://localhost:80/v1.12/containers/…: 409”

    Unfortunately I’m not familiar with the Java client library.

    My suggestion would be to try using the regular command-line client (kubectl). If that works, then you know the problem is in the Java client library or your usage of it. If using the command line client doesn’t work, then there will be more people who can help you (since a lot more people are familiar with the command-line client than with the Java client library).

    In other words
    % kubectl delete pods … # –cascade=true by default
    % kubectl delete services …

    I’m curious why you need step (4) and (5). Step (4) should happen automatically when you delete the pod, and step (5) should happen automatically in the background.

    If the two lines of “kubectl delete” work, then the problem is with the Java client library or your usage of it. As a starting point I would suggest remove calling deleteContainers() and removeImage() from your Java code and see if that helps. I think those steps are unnecessary.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.