我尝试使用docker api python客户端从GitHub存储库构建docker镜像。
这是我尝试过的: 来自views.py
if request.method == 'POST':
post_data = request.POST.copy()
post_data.update({'user': request.user.pk})
form = TarFromGithubForm(post_data)
if form.is_valid():
deployment = gitHubModel()
deployment.name = form.cleaned_data['name']
deployment.user = request.user
deployment.archive = form.cleaned_data['archive']
dpath = deployment.archive
print(deployment.archive)
deployment.save()
tag = deployment.name.lower()
client = docker.from_env()
client.images.build(path=dpath, tag=tag)
messages.success(request, 'Your deployment from github repository has been created successfully!')
return HttpResponseRedirect(reverse('users:deployments:repo'))
此处在归档输入字段中,用户将提供github存储库URL。
它会抛出错误:
/ user / deployment / new / github上的APIError 500服务器错误:内部服务器错误("错误检测远程https://github.com/Abdul-Rehman-yousaf/testing的内容类型:不支持的内容类型" text / html; charset = utf-8"") 请求方法:POST 请求网址:http://127.0.0.1:8000/user/deployment/new/github Django版本:1.11.3 例外类型:APIError 例外价值:
500服务器错误:内部服务器错误("错误检测远程https://github.com/Abdul-Rehman-yousaf/testing的内容类型:不支持的内容类型" text / html; charset = utf-8"") 异常位置:/Users/abdul/IstioVirEnv/lib/python3.6/site-packages/docker/errors.py in create_api_error_from_http_exception,第31行 Python可执行文件:/ Users / abdul / IstioVirEnv / bin / python Python版本:3.6.1
答案 0 :(得分:0)
detecting content type for remote
unsupported Content-Type "text/html; charset=utf-8""
你确定你通过了正确的网址吗?如果在这种情况下你想要Dockerfile它将在:https://raw.githubusercontent.com/Abdul-Rehman-yousaf/testing/master/Dockerfile
您可以使用wget
发出一个简单的http请求,以确保您传递的是正确的网址:
wget https://raw.githubusercontent.com/Abdul-Rehman yousaf/testing/master/Dockerfile
所以看来你传递的是一个错误的url,另一种方法是克隆repo并将代码传递给Dockerfile,它将通过将所需的文件或文件夹复制到容器等来跟踪它的内容过程。 ..