New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
copyFileFromContainer returns an empty file if file permissions inside docker container don't have w for owner user #681
Comments
Ok. I found the reason. If the file is created with r only permissions the library will first create the file and give it their atributes, and once it tries to write to the file, it will fail. This is a bug. For now, this is my solution: replace server.copyFileFromContainer with:
|
Hi @xtrm0, thanks for providing this information. |
This was my docker file for gensecserver:
This was starter.:
And this the genKeys.sh:
The server.jar is irrelevant here as it was not used. So you can just replace that with any command that will keep running, like for instance "/usr/bin/sleep 99999999". |
In short, this should reproduce the bug:
starter.sh:
java to run on host:
|
Someone on our team is reporting the same problem. I can successfully copy a file from the container on my linux machine but the same code is failing on their macs. I haven't looked at the code so this may be totally wrong but is it possible that the code is doing:
instead of
IIRC on Linux the order won't matter since you retain the permissions from when the file was opened. That's why one common trick for getting a huge buffer is to open a temporary file and immediately delete it. It's still available to the application but is inaccessible by anyone else. Changing the file permissions so it's read-only won't affect the application until the file is closed. However Macs may be different - they might check the permissions on every access and changing the permissions immediately would block future writes. It's more secure but it breaks this technique for copying a file. That's pure conjecture though since I don't know if that's the actual behavior on macs or if the code is actually doing the file write and changing permissions in that order. |
A follow-up - my coworkers stepped through it with a debugger. It looks like it's a known issue in the Apache commons 'compress' library that was recently fixed. We're checking which version of the library we're actually using once all of the dependencies are resolved. The details was that it's a 'bad header' error in the tar archiver. They were confused by that until I pointed out that a docker image is a stack of tar files. I hope that info helps other people who see this or similar errors. |
We believe this is all down to an issue which we've inherited from docker-java, docker-java/docker-java#1079. This affects the docker-java netty implementation. I'm testing a fix in the form of #817, which seems to be working well so far. There is a workaround which works without #817: we have an alternative OkHttp transport that is already bundled with Testcontainers, as a future replacement for netty. The OkHttp transport is immune to this bug, so may be a useful interim workaround. To activate it, add the line |
We've released 1.8.3 which hopefully fixes this issue. Please could you try it out? |
It works for us.
…On Sun, Aug 5, 2018 at 3:37 PM, Richard North ***@***.***> wrote:
We've released 1.8.3
<https://github.com/testcontainers/testcontainers-java/releases/tag/1.8.3>
which hopefully fixes this issue. Please could you try it out?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#681 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAMqTOiD8UqNLvNCIiR4-yK2u08J9TTsks5uN2WogaJpZM4Tx4dM>
.
|
Whenever I copyFileFromContainer I always get an empty file, even though the same command using
docker cp
executes correctly.I'm not sure how to provide more information, so here goes my configuration:
I have a docker image with the following start script, that generates the file server_pub.pem:
And when I run outside this image the copyFileFromContainer I get an empty file:
But if I run docker cp I get a valid file:
The text was updated successfully, but these errors were encountered: