从GitHub仓库build立Docker镜像

我正在尝试使用docker api python客户端从GitHub存储库构builddocker镜像。

以下是我所尝试的: 从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')) 

这里在档案input栏中用户将提供github仓库的url。

它会抛出一个错误:

在/ user / deployment / new / github上的API错误500服务器错误:内部服务器错误(“检测远程的内容types错误https://github.com/Abdul-Rehman-yousaf/testing:unsupported Content-Type”text / html; charset = utf-8“”)请求方法:POST请求URL: http : //127.0.0.1 :8000/user/deployment/new/github Django版本:1.11.3exceptiontypes:APIErrorexception值:
500服务器错误:内部服务器错误(“错误检测远程的内容typeshttps://github.com/Abdul-Rehman-yousaf/testing :不支持的内容types”文本/ HTML;字符集= utf-8“”)exception位置:/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

detecting content type for remote unsupported Content-Type "text/html; charset=utf-8""你确定你传递了正确的URL吗?如果在这种情况下你想要Dockerfile,它将在https:// raw。 githubusercontent.com/Abdul-Rehman-yousaf/testing/master/Dockerfile

你可以使用wget做一个简单的http请求,以确保你传递正确的url:

wget https://raw.githubusercontent.com/Abdul-Rehman yousaf/testing/master/Dockerfile

所以看起来你正在传递一个错误的url,另一种方法是克隆回购,并将代码传递到Dockerfile,它将通过复制所需的文件或文件夹到容器等内容过程。