Remote API for application code updating

I’m using the java client and working with remote api on a limited implementation so far. My goal is to use a since image to spin up multiple containers then dynamically enable those containers to access a host directly that has developer code. In this case it is a container running Tomcat and .war files.

I don’t want to include the .war files in the images since that would created hundreds of images. Via the command line I can copy a .war into a container, which could okay but there doesn’t seem to be an option for that in the remote api. Ideally, I would like to make mounts points available for the container to use and that the developer can continuously update their code. If that’s possible it would be great, but as of yet I haven’t found the right combination. I have tried HostConfig : Binds:[“/host/path:/container/path”] which shows up in the container info but doesn’t seem to do what I wish. Any and all help would be greatly appreciate.

  • 'Unable to revive connection’ errors when running ES in Docker container network
  • Problems running kapacitor localinstall inside dockerfile
  • create volume in docker and use it in a container
  • Docker: input from web UI user to Docker run Python interpreter
  • Allow nginx to read docker.sock
  • Rundeck is not showing docker containers in nodes
  • Below is the java method I use to create the container.

    public int doIt(){
    
        int ri = 0;
    
        JSONObject object = new JSONObject();
        JSONObject aObject = new JSONObject();
        JSONObject bObject = new JSONObject();
    
        JSONArray list = new JSONArray();
    
        try {
        object.put("Image", "test/tomcat");
    
        aObject.put("/home/mkwalter/tomcat/webapps", new JSONObject());
        object.put("Volumes", aObject);
    
        list.add("/home/mkwalter/tomcat/webapps:/usr/local/tomcat/webapps");
        bObject.put("Binds",list);
        object.put("HostConfig", bObject);
    
    
    
        System.out.println("object.toString before try " + object.toString());
    
        } catch (Exception e) {
            System.out.println(e);
        }
    
        try {
    
            HttpClient httpClient = HttpClientBuilder.create().build(); //Use this instead 
    
             HttpPost request = new HttpPost("http://192.168.1.97:4243/containers/create?name=");
             StringEntity params = new StringEntity(object.toString());
             request.addHeader("content-type", "application/json");
                request.setEntity(params);
                HttpResponse response = httpClient.execute(request);
    
                System.out.println("Response Code : " 
                        + response.getStatusLine().getStatusCode());
                ri = response.getStatusLine().getStatusCode();
    
        } catch (Exception ex){
            System.out.println(ex);
        }
        return ri;
    }
    

    Below is the inspect of the container created by the method.

    [
    {
        "Id": "d725ec70fd0edb012850f031faf6e50c7362491db1165c7b69684259529d124c",
        "Created": "2016-06-05T00:40:56.0745768Z",
        "Path": "catalina.sh",
        "Args": [
            "run"
        ],
        "State": {
            "Status": "created",
            "Running": false,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 0,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "0001-01-01T00:00:00Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:50630603d091a8a26abbf7e136a588a956a236a3f0ee4433d3bdb4968987b22a",
        "ResolvConfPath": "",
        "HostnamePath": "",
        "HostsPath": "",
        "LogPath": "",
        "Name": "/romantic_dijkstra",
        "RestartCount": 0,
        "Driver": "aufs",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [
                "/home/mkwalter/tomcat/webapps:/usr/local/tomcat/webapps"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": null,
            "RestartPolicy": {
                "Name": "",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Dns": null,
            "DnsOptions": null,
            "DnsSearch": null,
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "StorageOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": null,
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": -1,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "BlkioIOps": 0,
            "BlkioBps": 0,
            "SandboxSize": 0
        },
        "GraphDriver": {
            "Name": "aufs",
            "Data": null
        },
        "Mounts": [
            {
                "Source": "/home/mkwalter/tomcat/webapps",
                "Destination": "/usr/local/tomcat/webapps",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Name": "0bc51a207c05837c276dce77d697412715616c8353cb8d6fef3cfcb3ba5b3d3e",
                "Source": "/var/lib/docker/volumes/0bc51a207c05837c276dce77d697412715616c8353cb8d6fef3cfcb3ba5b3d3e/_data",
                "Destination": "/home/mkwalter/tomcat/webapps",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ],
        "Config": {
            "Hostname": "d725ec70fd0e",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "8080/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/tomcat/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "LANG=C.UTF-8",
                "JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre",
                "JAVA_VERSION=7u101",
                "JAVA_DEBIAN_VERSION=7u101-2.6.6-1~deb8u1",
                "CATALINA_HOME=/usr/local/tomcat",
                "TOMCAT_MAJOR=7",
                "TOMCAT_VERSION=7.0.69",
                "TOMCAT_TGZ_URL=https://www.apache.org/dist/tomcat/tomcat-7/v7.0.69/bin/apache-tomcat-7.0.69.tar.gz"
            ],
            "Cmd": [
                "catalina.sh",
                "run"
            ],
            "Image": "test/tomcat",
            "Volumes": {
                "/home/mkwalter/tomcat/webapps": {}
            },
            "WorkingDir": "/usr/local/tomcat",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": null,
            "SandboxKey": "",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "",
                    "EndpointID": "",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": ""
                }
            }
        }
    }
    ]
    

    Sorry for taking up so much space.

    The string that the java creates is below.

    {"Image":"test\/tomcat","HostConfig":{"Binds":["\/home\/mkwalter\/tomcat\/webapps:\/usr\/local\/tomcat\/webapps"]},"Volumes":{"\/home\/mkwalter\/tomcat\/webapps":{}}}

    Response Code : 201

  • STDIN not getting attached to restarted docker container
  • Ansible Docker Container - Clone Private Repo
  • Have docker not let a program bind a port to localhost
  • “java.net.NoRouteToHostException: No route to host” between two Docker Containers
  • Exposing ports to all containers, not only the host
  • Docker swarm load balancing - How to give common name to the service?
  • One Solution collect form web for “Remote API for application code updating”

    Your current JSON is of the format

    {
      "Image": "test/tomcat",
      "HostConfig": {
        "Binds": [
          "/home/mkwalter/tomcat/webapps:/usr/local/tomcat/webapps"
        ]
      },
      "Volumes": {
        "/home/mkwalter/tomcat/webapps": {
    
        }
      }
    }
    

    You Should be posting a request of the format

    {
      "Image": "test/tomcat",
      "HostConfig": {
        "Binds": [
          "/home/mkwalter/tomcat/webapps:/usr/local/tomcat/webapps"
        ]
      },
      "Volumes": {
        "/usr/local/tomcat/webapps":{}
      }
    }
    

    here is the code update u will need to make to fix this

    JSONObject object = new JSONObject();
        JSONObject aObject = new JSONObject();
        JSONObject bObject = new JSONObject();
    
        JSONArray list = new JSONArray();
    
        try {
        object.put("Image", "test/tomcat");
    
        aObject.put("/usr/local/tomcat/webapps", new JSONObject());
        object.put("Volumes", aObject);
    
        list.add("/home/mkwalter/tomcat/webapps:/usr/local/tomcat/webapps");
        bObject.put("Binds",list);
        object.put("HostConfig", bObject);
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.