【问题标题】:Docker build ubuntu:xenial issueDocker 构建 ubuntu:xenial 问题
【发布时间】:2016-03-29 14:06:26
【问题描述】:

我尝试在 Jenkins 中使用 docker-py 构建一个 docker 镜像。

脚本如下所示:

# Let's build the toolchain-base-image
from io import BytesIO
from docker import Client
from pprint import pprint
import sys

cli = Client(base_url="tcp://127.0.0.1:4243")
#cli = Client(base_url='unix://var/run/docker.sock')
GCC_VERSION_TAG="4_9"
with open("/path/to/docker-" + GCC_VERSION_TAG + "-gcc-base-image-dockerfile", mode="r") as dockerfile:
  f = BytesIO(dockerfile.read().encode('utf-8'))
  try:
      response = [pprint(line["stream"]) for line in cli.build(fileobj=f, nocache=False, rm=True, tag='gcc49/toolchain-base_'+GCC_VERSION_TAG, decode=True, pull=True)]
  except:
      raise IOError("Invalid Dockerfile!")
  if response != "None":
      pprint(response[0])

print "Create container"
container = cli.create_container(image='gcc49/toolchain-base_' + GCC_VERSION_TAG + ':latest',stdin_open=True, tty=True, volumes=['/ssd', '/opt', '/nfs/'], host_config=cli.create_host_config(binds=['/ssd:/ssd:rw','/opt/:/opt:ro','/nfs:/nfs:rw']))
print "Start container"
cli.start(container=container.get('Id'))
log_stream_list = []
[log_stream_list.append(l) for l in cli.logs(container, stream=True)]

print "".join(log_stream_list)

我的 dockerfile 看起来像这样:

FROM ubuntu:16.04
MAINTAINER Gino
ENV CMAKE_TOOLCHAIN_FILE /path/to/toolchainfile.toolchain
ENV SOURCE_DIR /path/to/src_root
RUN apt-get update 
RUN apt-get install -y python-cheetah build-essential gcc-4.9 cmake
RUN groupadd group
RUN useradd -G group -m -s /bin/bash user 
RUN echo "user:user" | chpasswd
ENV HOME /home/user
ENV SHELL /bin/bash
ENV JAVA_HOME /opt/jdk1.8.0_65/
RUN mkdir -p /home/user/docker-build
WORKDIR /home/user/docker-build
# Set permissions
RUN chown -R user:group /home/*
USER user
# Start build on run
ENTRYPOINT cmake -DBUILD_JAVA=0 -DCMAKE_BUILD_TYPE=DeveloperRelease -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DPROJECT_CONFIGURATION="project@${SOURCE_DIR}/dir" ${SOURCE_DIR} && make -j4

我的问题:

15:37:27 [docker-test_job] $ python /tmp/hudson5834793409651253293.py
15:37:29 u'Step 1 : FROM ubuntu:16.04\n'
15:37:29 Traceback (most recent call last):
15:37:29   File "/tmp/hudson5834793409651253293.py", line 15, in <module>
15:37:29     raise IOError("Invalid Dockerfile!")
15:37:29 IOError: Invalid Dockerfile!
15:37:29 Build step 'Execute Python script' marked build as failure
15:37:29 Stopping all containers
15:37:29 Finished: FAILURE

当我用 ubuntu:14.04 尝试它时,它工作得很好。有人有想法吗? 感谢您的帮助!

更新:一些附加信息:Docker 1.5 + Ubuntu 12.04 LTS。 当我在控制台上运行时

docker build -t name/tag -f dockerfilename .

它也可以正常工作,并且 docker 会按预期构建图像。

【问题讨论】:

  • 你试过了吗:FROM ubuntu:latest 另外,为什么不试试:FROM java:latest
  • 如果它在命令行中工作,那么我怀疑你的脚本中有什么东西。 但是 Docker Hub 不再支持 Docker 1.5,你确定你真的能够从 Docker Hub 中 ubuntu:16.04 吗?
  • @Sabmit ubuntu:latest 指向最新的 LTS 版本;鉴于 16.04 尚未发布,:latest 目前是14.04 的别名,而不是16.04
  • 14.04 与最新相关。 ubuntu 14.04 97434d46f197 10 天前 188 MB ubuntu 最新 97434d46f197 10 天前 188 MB
  • @thaJeztah 是的,我也在怀疑:ubuntu 16.04 537089ecf650 10 天前 119 MB 但它有效。我也确定它在脚本中,但我不知道为什么它适用于 14.04 但不适用于 16.04。

标签: python ubuntu jenkins docker dockerfile


【解决方案1】:

现在可以了。我发现我不能使用pull=True。我认为返回码 > 0 回来了,詹金斯将其解释为错误。谢谢你的帮助。 :) 下面是有效的代码。

[pprint(line["stream"]) for line in cli.build(fileobj=f, nocache=False, rm=True, tag='gcc49/toolchain-base_'+GCC_VERSION_TAG, decode=True)]

更新

我错了。在上面的行中,我尝试匹配关键的“流”。但是如果 docker 拉取图像。没有这样的钥匙。

10:28:06  u'progress': u'[===================================>               ] 36.18 MB/50.84 MB',
10:28:06  u'progressDetail': {u'current': 36175872, u'total': 50841331},
10:28:06  u'status': u'Extracting'}

现在一切都清楚了。 :)

【讨论】:

    【解决方案2】:

    我猜您需要提供 Docker 文件的路径(包括 Dockerfile 的名称),而在您的 python 脚本中,您似乎只提供了 Dockerfile 所在的目录。换个零件试试

    open("/path/to/docker-" + GCC_VERSION_TAG + "-gcc-base-image", mode="r")'

    open("/path/to/docker-" + GCC_VERSION_TAG + "-gcc-base-image/dockerfilename", mode="r")

    看看有没有效果

    【讨论】:

    • 嗨,对不起 docker-" + GCC_VERSION_TAG + "-gcc-base-image 已经是文件名,我已经使用另一个 dockerfile 了,我只更改了 ubuntu 版本。我更新了我的帖子以使其更清楚它是一个 dockerfile。:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-15
    • 1970-01-01
    • 2019-09-27
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    相关资源
    最近更新 更多