【问题标题】:Build Docker image from GitHub repository从 GitHub 存储库构建 Docker 映像
【发布时间】:2018-01-05 11:37:00
【问题描述】:

我正在尝试使用 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 在 create_api_error_from_http_exception,第 31 行 Python 可执行文件:/Users/abdul/IstioVirEnv/bin/python Python 版本:3.6.1

【问题讨论】:

    标签: python django docker docker-build docker-api


    【解决方案1】:

    detecting content type for remoteunsupported 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,另一种方法是克隆 repo 并将代码传递给 Dockerfile,它将通过将所需的文件或文件夹复制到容器等来遵循它的内容过程。 ..

    【讨论】:

    • 我将存储库 url 传递为:https://github.com/Abdul-Rehman-yousaf/testing 并且 dockerfile 在根目录中
    • 用户是否需要传递 dockerfile url 而不是主存储库 url,其中 dokefile 在此存储库的根目录中?
    • 向主 github 存储库发出 http 请求不是使用 git 存储库的正确方法,因此将主存储库传递给诸如 python 请求之类的 http 请求将响应 [ text/html ] 为您从引用中看到,在这种情况下,您需要使用 github api 克隆 repo,并在克隆 repo 后确保将代码传递给 Dockerfile,因为这是您可以构建容器的唯一文件。跨度>
    • 我已经尝试过该方法,在这种情况下,问题是目录,我尝试过的方法是我创建了一个临时目录并将 GitHub 存储库克隆到该目录中,然后我如何提供该目录的路径到 docker build 方法?
    • 现在如果我通过https://github.com/Abdul-Rehman-yousaf/testing.git。存储库的 git 路径它给出的 BuildError 为 The command '/bin/sh -c npm install' returned a non-zero code: 1
    猜你喜欢
    • 2015-01-01
    • 2016-06-24
    • 2021-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-12
    • 2021-06-19
    • 1970-01-01
    相关资源
    最近更新 更多