Can not pass `fileobj` together with `path` context to `build`
See original GitHub issueIt seems to be impossible to pass ephemeral Dockerfile
to build command together with build context. Here is command line use case:
docker build -t . -f-<<EOF
Lorem ipsum docker file
EOF
According to the documentation https://docker-py.readthedocs.io/en/stable/images.htmlit should be possible to pass Dockerfile
as file object, but in current implementation path
param with context is ignored.
Here is path that fix part of this issue (it don’t work when path.startswith(('http://', 'https://','git://', 'github.com/', 'git@'))
)
diff --git a/docker/api/build.py b/docker/api/build.py
index 0486dce..711def2 100644
--- a/docker/api/build.py
+++ b/docker/api/build.py
@@ -133,7 +133,7 @@ class BuildApiMixin(object):
if not fileobj:
raise TypeError("You must specify fileobj with custom_context")
context = fileobj
- elif fileobj is not None:
+ elif path is None and fileobj is not None:
context = utils.mkbuildcontext(fileobj)
elif path.startswith(('http://', 'https://',
'git://', 'github.com/', 'git@')):
@@ -149,7 +149,7 @@ class BuildApiMixin(object):
lambda x: x != '' and x[0] != '#',
[l.strip() for l in f.read().splitlines()]
))
- dockerfile = process_dockerfile(dockerfile, path)
+ dockerfile = process_dockerfile(dockerfile, path, fileobj)
context = utils.tar(
path, exclude=exclude, dockerfile=dockerfile, gzip=gzip
)
@@ -332,7 +332,13 @@ class BuildApiMixin(object):
log.debug('No auth config found')
-def process_dockerfile(dockerfile, path):
+def process_dockerfile(dockerfile, path, fileobj):
+ if fileobj is not None:
+ return (
+ '.dockerfile.{0:x}'.format(random.getrandbits(160)),
+ fileobj.read()
+ )
+
if not dockerfile:
return (None, None)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:12 (1 by maintainers)
Top Results From Across the Web
Unable to copy file to server on build. Access to path is denied
Running SysInternals procexp: devenv.exe sitting on the file. Unloading project didn't work but after closing solution I could delete System.Web.WebPages.
Read more >build.py - Google Git
raise TypeError("Either path or fileobj needs to be provided.") if gzip and encoding is not None: raise errors.DockerException(. 'Can not use custom ...
Read more >python - Should I pass in filenames to be opened, or open files?
No, what you're doing still isn't duck typing. A hasattr(fileobj, 'read') test would be duck typing; an isinstance(fileobj, str) test is not.
Read more >tarfile — Read and write tar archive files ... - Python Docs
A TarFile object can be used as a context manager in a with statement. It will automatically be closed when the block is...
Read more >IO tools (text, CSV, HDF5, …) — pandas 1.5.2 documentation
int32, 'c': 'Int64'} Use str or object together with suitable na_values settings to preserve and not interpret dtype. If converters are specified, they...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@danieladams456 I end up with the PR that they don’t want to merge and this simple polyfill that might help you:
And then simply:
If dockerfile it’s not part of context for some reason, it have to be affected to be dockerized. I know that it can be passed as absolute path, but if dockerfile is ephemeral it requires saving is somewhere is filesystem which is little more complicated. Generally it py lib lacs functionality of cli, and arguments could be simplified a bit.