0
我使用Docker Remote Api和python請求v2.2.1來運行exec語句。這是我正在使用的代碼:使用Docker遠程API運行exec時出錯500
import requests
import json
containerName = 'my_container_name'
startContainerRequest = requests.post('http://127.0.0.1:4243/containers/' + containerName + '/start')
print startContainerRequest.status_code #result: 204
payload = {'Cmd':["date"]}
headers = {'Content-type': 'application/json'}
execCreateRequest = requests.post('http://127.0.0.1:4243/containers/' + containerName + '/exec', data=json.dumps(payload), headers=headers)
print execCreateRequest.status_code #result: 201
execStartRequest = requests.post('http://127.0.0.1:4243/exec/' + execCreateRequest.json()['Id'] + '/start', headers=headers)
print execStartRequest.status_code #result: 500
print execStartRequest.text #EOF
最後一個REST請求失敗。 Exec inspect使用相同的ID,所以ID不是問題。在負載中使用不同於日期的命令也會失敗。我嘗試了不同的容器,但得到了相同的結果。 從終端工程運行docker exec my_container_name date
。
這裏是我的DOCKER_OPTS從/ etc /默認/泊塢窗:
DOCKER_OPTS="--dns *privateDNS* --dns 8.8.8.8 -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock"
是否添加JSON身體到'/ start'幫助? – Matt
是的,這是訣竅。它應該像那樣工作,還是這是其餘API中的錯誤?隨意將您的評論轉換爲答案,我會接受並註冊它 – Jakob
不確定,也許在github上創建一個問題來檢查。一些JSON API至少需要'{}',因此它解析爲JSON。 – Matt