Unable to start a Docker container through Remote Docker Java API

I am a beginner to Docker technology and I have been attempting to build up a Java app which is capable of starting and stopping existing Docker containers.

For this purpose I had been using Java Docker API client – dockerjava.
https://github.com/docker-java/docker-java and I had been using https://github.com/docker-java/docker-java/wiki test cases to observe how this API works as I have not been able to find any related tutorials.

  • Share directory or volume with container from host
  • docker container stops unexpectedly
  • Docker as sandbox environment
  • docker nginx deployment entrypoint
  • mongodb replica set master “stateStr” : “REMOVED”
  • How to expose port from host to container in Docker?
  • Using the code, I have enabled the Java application to create a Docker container using the following code sample.

    CreateContainerResponse container = client.createContainerCmd("chirangaalwis/docker-whale")
                    .withCmd("/bin/sh -c '/usr/gam")
                    .exec();
    

    But I have been unsuccessful in starting up the container I created using the Java application and it throws out the following exception:

    Exception in thread "main" com.github.dockerjava.api.InternalServerErrorException: Cannot start container 485386a92b34c5aaf53793207e5c6a8146295b23602c9d0adf86d64a1b27d031: write /sys/fs/cgroup/cpuset/docker/485386a92b34c5aaf53793207e5c6a8146295b23602c9d0adf86d64a1b27d031/cpuset.cpus: invalid argument
    
        at com.github.dockerjava.core.util.ResponseStatusExceptionFilter.filter(ResponseStatusExceptionFilter.java:53)
        at org.glassfish.jersey.client.ClientFilteringStages$ResponseFilterStage.apply(ClientFilteringStages.java:139)
        at org.glassfish.jersey.client.ClientFilteringStages$ResponseFilterStage.apply(ClientFilteringStages.java:127)
        at org.glassfish.jersey.process.internal.Stages.process(Stages.java:171)
        at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:259)
        at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:671)
        at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:668)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
        at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
        at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:668)
        at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:428)
        at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:334)
        at com.github.dockerjava.jaxrs.StartContainerCmdExec.execute(StartContainerCmdExec.java:28)
        at com.github.dockerjava.jaxrs.StartContainerCmdExec.execute(StartContainerCmdExec.java:13)
        at com.github.dockerjava.jaxrs.AbstrDockerCmdExec.exec(AbstrDockerCmdExec.java:53)
        at com.github.dockerjava.core.command.AbstrDockerCmd.exec(AbstrDockerCmd.java:29)
        at com.github.dockerjava.core.command.StartContainerCmdImpl.exec(StartContainerCmdImpl.java:53)
        at lk.ac.iit.java_docker.DockerWithJavaClass.main(DockerWithJavaClass.java:36)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
    

    This was the code sample I am using for the above purpose:

    import com.github.dockerjava.api.DockerClient;
    import com.github.dockerjava.api.command.CreateContainerResponse;
    import com.github.dockerjava.api.model.Container;
    import com.github.dockerjava.api.model.Info;
    import com.github.dockerjava.api.model.SearchItem;
    import com.github.dockerjava.core.DockerClientBuilder;
    import com.kpelykh.docker.client.model.ContainerCreateResponse;
    
    import java.util.List;
    
    /**
     * Created by chiranga on 7/29/15.
     */
    public class DockerWithJavaClass {
        public static void main(String[] args) {
            DockerClient client = DockerClientBuilder.getInstance("http://localhost:2375").build();
    
            System.out.println("This is my client " + client);
            System.out.println();
    
            Info info = client.infoCmd().exec();
            System.out.println(info);
            System.out.println();
    
            CreateContainerResponse container = client.createContainerCmd("chirangaalwis/docker-whale")
                    .withCmd("/bin/sh -c '/usr/gam")
                    .exec();
    
            client.startContainerCmd(container.getId()).exec();
        }
    }
    

    Based on the exception messsage, I changed the code such that the id is printed along with the full path given, which led to another new exception as follows:

    Exception in thread "main" com.github.dockerjava.api.DockerException
        at com.github.dockerjava.core.util.ResponseStatusExceptionFilter.filter(ResponseStatusExceptionFilter.java:55)
        at org.glassfish.jersey.client.ClientFilteringStages$ResponseFilterStage.apply(ClientFilteringStages.java:139)
        at org.glassfish.jersey.client.ClientFilteringStages$ResponseFilterStage.apply(ClientFilteringStages.java:127)
        at org.glassfish.jersey.process.internal.Stages.process(Stages.java:171)
        at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:259)
        at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:671)
        at org.glassfish.jersey.client.JerseyInvocation$1.call(JerseyInvocation.java:668)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
        at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
        at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
        at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:668)
        at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:428)
        at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:334)
        at com.github.dockerjava.jaxrs.StartContainerCmdExec.execute(StartContainerCmdExec.java:28)
        at com.github.dockerjava.jaxrs.StartContainerCmdExec.execute(StartContainerCmdExec.java:13)
        at com.github.dockerjava.jaxrs.AbstrDockerCmdExec.exec(AbstrDockerCmdExec.java:53)
        at com.github.dockerjava.core.command.AbstrDockerCmd.exec(AbstrDockerCmd.java:29)
        at com.github.dockerjava.core.command.StartContainerCmdImpl.exec(StartContainerCmdImpl.java:53)
        at lk.ac.iit.java_docker.DockerWithJavaClass.main(DockerWithJavaClass.java:39)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
    

    The following change was made to the code before I got the above new exception:

    client.startContainerCmd("/sys/fs/cgroup/cpuset/docker/" + container.getId() + "/cpuset.cpus").exec();
    

    I am totally new to this technology and I would be grateful if someone could provide me with a well explained solution to this problem and if any better alternative(s) to achieve this task exist, please specify.

  • A completely closed source docker container
  • /home/web/.gem/ruby/2.2.0/gems/redis-3.2.1/lib/redis/connection/ruby.rb:152:in `getaddrinfo': getaddrinfo: Name or service not known (SocketError)
  • Running Python Script in Background Infinitely
  • Building a Docker Image with rstan on rocker/verse
  • Can not give any access using Docker
  • Not receiving UDP traffic on port exposed in Docker container running on Docker for Windows. How to debug?
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.