我正在尝试使用docker api python客户端从GitHub存储库构建docker镜像。从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。
它抛出一个错误:
APIError at /user/deployment/new/github 500 Server Error: Internal Server Error ("error detecting content type for remote https://github.com/Abdul-Rehman-yousaf/testing : unsupported Content-Type "text/html; charset=utf-8"") Request Method: POST Request URL: http://127.0.0.1:8000/user/deployment/new/github Django Version: 1.11.3 Exception Type: APIError Exception Value:
500 Server Error: Internal Server Error ("error detecting content type for remote https://github.com/Abdul-Rehman-yousaf/testing : unsupported Content-Type "text/html; charset=utf-8"") Exception Location: /Users/abdul/IstioVirEnv/lib/python3.6/site-packages/docker/errors.py in create_api_error_from_http_exception, line 31 Python Executable: /Users/abdul/IstioVirEnv/bin/python Python Version: 3.6.1
I '传递知识库URL为:'https://github.com/Abdul-Rehman-yousaf/testing '和dockerfile在根 –
用户是否需要通过dockerfile url而不是主要的存储库url,在这个存储库的根目录中的dockefile? –
向主github回购制作一个http请求并不是正确的方式来使用git回购,所以将主repo传递给像python请求这样的http请求,将会像从trackback中看到的那样用[text/html]进行响应,在这种情况下,您需要使用github api克隆repo,并且在克隆repo之后确保您将代码传递给Dockerfile,因为这是您可以构建容器的唯一文件。 – misraX