Docker-py: Dockerfile 'copy' not handled correctly

Created on 3 Mar 2016  路  3Comments  路  Source: docker/docker-py

Based on documentation example, I modified the Dockerfile content.
However the following code does not find python-redfish.src.tar.gz

from io import BytesIO
from docker import Client
dockerfile = '''
FROM debian:jessie
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
        apt-get install -y apt-utils && \
        apt-get install -y python-pip
COPY python-redfish.src.tar.gz /python-redfish.src.tar.gz
CMD ["/bin/sh"]
'''
f = BytesIO(dockerfile.encode('utf-8'))
cli = Client(base_url='unix://var/run/docker.sock')
response = [line for line in cli.build(fileobj=f, rm=True, tag='essai')]
print(response)

It rises the following error,

...
'{"errorDetail":{"message":"lstat python-redfish.src.tar.gz: no such file or directory"},"error":"lstat python-redfish.src.tar.gz: no such file or directory"}\r\n']

Using the same content as the script into a Dockerfile

(python2)[uggla@ugglalaptop docker-py_debug]$ ll
total 1712
-rw-rw-r-- 1 uggla uggla     199 Mar  3 23:03 dockerbuild.py
-rw-rw-r-- 1 uggla uggla     232 Mar  3 22:56 Dockerfile
-rw-rw-r-- 1 uggla uggla     484 Mar  3 22:52 example.py
-rw-rw-r-- 1 uggla uggla 1738436 Mar  3 22:04 python-redfish.src.tar.gz
(python2)[uggla@ugglalaptop docker-py_debug]$ cat Dockerfile
FROM debian:jessie
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
        apt-get install -y apt-utils && \
        apt-get install -y python-pip
COPY python-redfish.src.tar.gz /python-redfish.src.tar.gz
CMD ["/bin/sh"]

It builds correctly

(python2)[uggla@ugglalaptop docker-py_debug]$ docker build .
Sending build context to Docker daemon 1.742 MB
Step 1 : FROM debian:jessie
 ---> f50f9524513f
Step 2 : ENV DEBIAN_FRONTEND noninteractive
 ---> Using cache
 ---> b3edf5bbfd90
Step 3 : RUN apt-get update &&         apt-get install -y apt-utils &&         apt-get install -y python-pip
 ---> Using cache
 ---> b00aa7d0ac65
Step 4 : COPY python-redfish.src.tar.gz /python-redfish.src.tar.gz
 ---> 26116a613291
Removing intermediate container 786dca1499bb
Step 5 : CMD /bin/sh
 ---> Running in ac8eb5f0fcff
 ---> dc66ea06ef5c
Removing intermediate container ac8eb5f0fcff
Successfully built dc66ea06ef5c

This code as well

# coding=utf-8
from docker import Client

cli = Client(base_url='unix://var/run/docker.sock')


response = [line for line in cli.build(
    path='.',
    tag='essai',
    rm=True)]

print(response)

Investigating a bit more, I found that the context seems not managed correctly as soon as we use the fileobj parameter.

The files used :
docker-py_debug.tar.gz

Most helpful comment

Also looking for some clarification on this. Trying to pass a Dockerfile with fileobj using docker-py version 1.10.6. It fails with a error: lstat testfile: no such file or directory but that file is definitely in the directory. I've tried to implement the custom_context param, but that errors with an unexpected EOF

I'm trying to implement with a simple script similar to the fileobj script above. Is this a bug or am i missing something in the documentation?

All 3 comments

You need to use custom_context. See #209 and the docs

Thanks @shin- for the prompt answer !
Sorry the doc is not so clear on that point.

So I need to pass a tar file which include my files + the Dockerfile into fileobj and set custom_context=True.

Do I understand well ? If yes, is it still possible to specify a specific Dockerfile name (ex : Dockerfile.debian)

Also looking for some clarification on this. Trying to pass a Dockerfile with fileobj using docker-py version 1.10.6. It fails with a error: lstat testfile: no such file or directory but that file is definitely in the directory. I've tried to implement the custom_context param, but that errors with an unexpected EOF

I'm trying to implement with a simple script similar to the fileobj script above. Is this a bug or am i missing something in the documentation?

Was this page helpful?
0 / 5 - 0 ratings