madpeter
(Madpeter)
February 8, 2023, 8:04pm
1
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.
meyay
(Metin Y.)
February 8, 2023, 11:36pm
2
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
madpeter
(Madpeter)
February 9, 2023, 12:32am
3
thanks used your example to clean up my config maker and tested using the curl command ^+^
now to work out what I have broken ^+^
madpeter
(Madpeter)
February 9, 2023, 12:55am
4
found it
the post request with a body requires the header Content-Length to be set.
meyay
(Metin Y.)
February 9, 2023, 6:58am
5
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