Dockerfile 'copy' not handled correctly
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 1.7k
- Avg merge
- 13d 8h
- Merged PRs (30d)
- 2
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the cli.build entry point and compare the fileobj and path='.' cases using the provided Dockerfile and docker-py_debug.tar.gz reproduction. Check how the build context is assembled for fileobj builds. Done means the fileobj example can build successfully and COPY python-redfish.src.tar.gz resolves as it does with path='.'.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, python
- Domain
- api, devops
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100