2017-07-29 646 views
0

我正在尝试使用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

回答

0

detecting content type for remoteunsupported Content-Type "text/html; charset=utf-8""你确定你通过正确的网址是什么?如果在这种情况下,你想要的Dockerfile这将是:

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

如此看来:https://raw.githubusercontent.com/Abdul-Rehman-yousaf/testing/master/Dockerfile

可以使用wget,以确保您传递正确的URL做一个简单的HTTP请求你的传递错误的URL,另一种方法是克隆回购,并将代码传递到Dockerfile,它将通过将所需的一个或多个文件夹复制到容器等内容过程来进行跟踪......

+0

I '传递知识库URL为:'https://github.com/Abdul-Rehman-yousaf/testing '和dockerfile在根 –

+0

用户是否需要通过dockerfile url而不是主要的存储库url,在这个存储库的根目录中的dockefile? –

+0

向主github回购制作一个http请求并不是正确的方式来使用git回购,所以将主repo传递给像python请求这样的http请求,将会像从trackback中看到的那样用[text/html]进行响应,在这种情况下,您需要使用github api克隆repo,并且在克隆repo之后确保您将代码传递给Dockerfile,因为这是您可以构建容器的唯一文件。 – misraX

相关问题