Docker engine API / Containers / Create [Error code: 500]

I am playing around making my own little thing to control docker via the socket
I have support for containers [list, inspect, logs ect…]
but I am having issues with the create command only responding with a 500 error

Endpoint: /containers/create?name=web-test
Payload: {"HostConfig":{"PublishAllPorts":false,"Binds":[],"AutoRemove":false,"NetworkMod - Pastebin.com
Method: Post (with header Content-Type set to application/json)
Api version: 1.42

cli command I am trying to recreate:

docker run -d --name web-test -p 7654:8000 crccheck/hello-world

I think there is something wrong with the payload I am sending but without any feedback from docker engine
I am just guessing on what is wrong.

I just tried it with curl:

# pull image
curl --unix-socket /var/run/docker.sock \
     -X POST \
     http:/v1.42/images/create?fromImage=crccheck/hello-world

# create container from existing image in local image cache
id=$( curl --unix-socket /var/run/docker.sock \
      -X POST \
      -H "Content-Type: application/json" \
      -d '{"Image": "crccheck/hello-world", "ExposedPorts": {"8000/tcp": {} },"HostConfig":{"PortBindings": { "8000/tcp": [ {"HostPort": "7654"  } ] }} }' \
      http://v1.42/containers/create?name=web-test | jq -r '.Id' )

# start existing container id
curl --unix-socket /var/run/docker.sock \
     -X POST \
     http://v1.42/containers/${id}/start
1 Like

thanks used your example to clean up my config maker and tested using the curl command ^+^
now to work out what I have broken ^+^

found it :slight_smile:

the post request with a body requires the header Content-Length to be set.

Glad you found the cause.

Have you checked whether a sdk for the docker api exists for your language of choice?
See: Develop with Docker Engine SDKs | Docker Documentation