Docker build ubuntu:xenial issue

I try to build a docker image with docker-py in Jenkins.

The scripts looks like this:

# 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)

My dockerfile looks like this:

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

My issue:

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

When I try it with ubuntu:14.04 it works pretty fine. Got anyone an idea?
Thanks for helping!

  • Automate adding new repository tags to Docker Registry Automated Build
  • Accessing docker container from iOS Simulator
  • Docker Cannot link to a non running container
  • Are Dockerfiles stored on my machine?
  • Certificate issue when using artifactory as docker registry
  • lost connection to mysql server during query after about 1000 seconds
  • Update: Some additional information: Docker 1.5 + Ubuntu 12.04 LTS.
    When I run on console

    docker build -t name/tag -f dockerfilename .
    

    it works too and the docker builds the image as expected.

  • Deploying and Accessing Database Inside Docker Container
  • Create new MongoDB instance based on existing data
  • How to get back to life docker container?
  • Docker Tomcat7 container not always starting correctly
  • can I mount subdir of volume in docker run command
  • gitlab can not change gitlab url ,i edit config,yml , gitlab.yml
  • 2 Solutions collect form web for “Docker build ubuntu:xenial issue”

    It works now. I figured out that I can’t use pull=True. I think a return code > 0 comes back and Jenkins interpret it as an error. Thanks for any help. 🙂 Below is the code which work.

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

    Update

    I was wrong. In upper line I try to match the key “stream”. But if docker pulls the image. There is no such key.

    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'}
    

    Now everything is clear. 🙂

    i’m guessing you need to give the path to the Docker file (including the name of your Dockerfile) while in your python script it seems like you are only providing the directory where Dockerfile is present. try changing the part

    open(“/path/to/docker-” + GCC_VERSION_TAG + “-gcc-base-image”, mode=”r”)’

    to

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

    and see if it works

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.