Search code examples
dockerremoteapi

How can I recreate 'docker run' using the remote API?


What do the remote API calls look like to do the equivalent of, say

$ docker run -d our-image

There's a high-level view of what docker run is doing here, and this is a related question.

I've tried coping the ContainerConfig portion of:

curl -X GET 'http://0.0.0.0:2375/images/our-image/json'

To this call:

curl -X POST -H "Content-Type: application/json" -d $CONTAINER_CONFIG 'http://0.0.0.0:2375/containers/create'

And then doing a docker run our-image and comparing, for both respective containers created, the output of:

curl -X GET 'http://0.0.0.0:2375/containers/<container-id>/json'

And I notice some fields like HostnamePath, and LogPath which are set in the version launched with docker run.


Solution

  • If I understand you correctly, you want to collect detailed information about the parameters passed from Docker client to Docker daemon. If so, try to use this workaround:

    cd /var/run
    sudo mv docker.sock docker.sock.orig
    sudo socat -v UNIX-LISTEN:/var/run/docker.sock,group=docker,perm=0660,reuseaddr,fork UNIX-CONNECT:/var/run/docker.sock.orig
    

    This command will dump all the client requests as JSON objects.