The json POST which I am trying to send from command line or as part of a program is getting erred out with 500 server error.
Docker logs don’t give enough information. For simplicity I used copy command with one json key-value pair to show the errors.
But this (copy) works from postman( screen shot attached). So I am thinking I am not sending the request properly or this is not tested in commandline by anyone??
Let me know how to proceed.
{u’Resource’: u’/test’}
POST /containers/02d89f931a8c/copy HTTP/1.1
Content-Type: application/json
{u’Resource’: u’/test’}
HTTP/1.1 500 Internal Server Error
Content-Type: text/plain; charset=utf-8
Server: Docker/1.9.1 (linux)
Date: Thu, 04 Feb 2016 00:33:56 GMT
Content-Length: 4
EOF
Directly on the socket.
root@sustx002dstd00q:/home/thing/divya/docker-remote-apis/sockets# socat - TCP:localhost:4243
POST /containers/84b200101ee1/copy HTTP/1.1
Content-Type: application/json
{“resource”:"/test"}
HTTP/1.1 500 Internal Server Error
Content-Type: text/plain; charset=utf-8
Server: Docker/1.9.1 (linux)
Date: Thu, 04 Feb 2016 00:35:01 GMT
Content-Length: 4
EOF
DOCKER LOGS
392 ^[[34mINFO^[[0m[6781] POST /containers/02d89f931a8c/attach?logs=0&stream=1&stdout=1&stdin=1&stderr=1
393 ^[[34mINFO^[[0m[6873] POST /v1.21/containers/create
394 ^[[34mINFO^[[0m[6874] POST /v1.21/containers/84b200101ee1f711a2bade0a4ec5d62a498d9b4b2c5c9c23ebafbba8c15fc134/attach?stderr=1&stdin=1&stdout=1&stream=1
395 ^[[34mINFO^[[0m[6874] POST /v1.21/containers/84b200101ee1f711a2bade0a4ec5d62a498d9b4b2c5c9c23ebafbba8c15fc134/start
396 ^[[34mINFO^[[0m[6874] No non-localhost DNS nameservers are left in resolv.conf. Using default external servers : [nameserver 8.8.8.8 nameserver 8.8.4.4]
397 ^[[34mINFO^[[0m[6874] IPv6 enabled; Adding default IPv6 external servers : [nameserver 2001:4860:4860::8888 nameserver 2001:4860:4860::8844]
398 ^[[34mINFO^[[0m[6874] POST /v1.21/containers/84b200101ee1f711a2bade0a4ec5d62a498d9b4b2c5c9c23ebafbba8c15fc134/resize?h=39&w=137
399 ^[[34mINFO^[[0m[7129] GET /version
400 ^[[34mINFO^[[0m[7173] GET /version
401 ^[[34mINFO^[[0m[7173] POST /containers/02d89f931a8c/copy
402 ^[[31mERRO^[[0m[7173] Handler for POST /containers/02d89f931a8c/copy returned error: EOF
403 ^[[31mERRO^[[0m[7173] HTTP Error ^[[31merr^[[0m=EOF ^[[31mstatusCode^[[0m=500
404 ^[[34mINFO^[[0m[7252] POST /containers/02d89f931a8c/copy
405 ^[[31mERRO^[[0m[7252] Handler for POST /containers/02d89f931a8c/copy returned error: Could not find the file /test in container 02d89f931a8c
406 ^[[31mERRO^[[0m[7252] HTTP Error ^[[31merr^[[0m=Could not find the file /test in container 02d89f931a8c ^[[31mstatusCode^[[0m= 500
407 ^[[34mINFO^[[0m[7268] POST /containers/84b200101ee1/copy
408 ^[[34mINFO^[[0m[7297] GET /version
409 ^[[34mINFO^[[0m[7297] POST /containers/02d89f931a8c/copy
410 ^[[31mERRO^[[0m[7297] Handler for POST /containers/02d89f931a8c/copy returned error: EOF
411 ^[[31mERRO^[[0m[7297] HTTP Error ^[[31merr^[[0m=EOF ^[[31mstatusCode^[[0m=500
412 ^[[34mINFO^[[0m[7498] GET /version
413 ^[[34mINFO^[[0m[7498] POST /containers/02d89f931a8c/copy
414 ^[[31mERRO^[[0m[7498] Handler for POST /containers/02d89f931a8c/copy returned error: EOF
415 ^[[31mERRO^[[0m[7498] HTTP Error ^[[31merr^[[0m=EOF ^[[31mstatusCode^[[0m=500
416 ^[[34mINFO^[[0m[7563] POST /containers/84b200101ee1/copy
417 ^[[31mERRO^[[0m[7563] Handler for POST /containers/84b200101ee1/copy returned error: EOF
418 ^[[31mERRO^[[0m[7563] HTTP Error ^[[31merr^[[0m=EOF ^[[31mstatusCode^[[0m=500
419 ^[[34mINFO^[[0m[7643] POST /v1.21/containers/84b200101ee1f711a2bade0a4ec5d62a498d9b4b2c5c9c23ebafbba8c15fc134/resize?h=56&w=165
CODE
#!/usr/bin/python
from time import ctime
import socket
import requests
import json
curl = "GET /version HTTP/1.1"
PORT = 4243
BUFSIZE = 1024
s = socket.socket()
s.connect((“127.0.0.1”,4243))
s.send(“GET /version HTTP/1.1\r\n\r\n”)
print s.recv(1024)
headers = “”“
POST /containers/02d89f931a8c/copy HTTP/1.1
Content-Type: {content_type}\r
\r\n”""
body = "{“Resource”: “/test”}"
body_bytes=json.loads(body)
print body_bytes
header_bytes = headers.format(
content_type=“application/json”,
)
payload = header_bytes + json.dumps(body_bytes)
print payload
s.send(payload)
print s.recv(1024)
s.close()