Build command fails when symlinks in docker folder are used
See original GitHub issueMy Docker image includes some files, which are symlinks pointing outside of docker folder, e.g.
$ ls -l include/
total 0
lrwxrwxrwx 1 dmitry dmitry 29 Mar 30 17:25 python3.5m -> /usr/local/include/python3.5m
Native docker client handles this correctly. Java File.getCanonicalFile()
follows symlinks, so TAR archive sent to Docker daemon contains usr/local/include/python3.5m/**
instead of expected include/python3.5m/**
, and as a result I get confusing errors about non-existent files.
I guess replacing FilePathUtil.relativize(File, File)
with the following code would work, but please check if this behavior does not break other usages.
public static String relativize(File baseDir, File file) {
try {
return baseDir.toPath()
.toRealPath(LinkOption.NOFOLLOW_LINKS)
.relativize(file.toPath().toRealPath(LinkOption.NOFOLLOW_LINKS))
.toString();
} catch (IOException e) {
throw new DockerClientException(e.getMessage(), e);
}
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Docker does not follow symlinks within build directory
The Options as I see them: Create a bash/sh script to copy the files into public after both repositories are setup.
Read more >Access denied when creating symlinks in docker-windows ...
I am running into access denied problems when creating symbolic links with windows-docker runners. The problem seems to be only happen when ...
Read more >Error when running docker build on any dockerfile: "unable to ...
Dockerfile', it throws the error "unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /home/xxx/yyy/Dockerfile: no ...
Read more >Docker Desktop release notes
A failed spawned command when building an extension no longer causes Docker Desktop to unexpectedly quit. Fixed a bug that caused extensions to...
Read more >too many links in /var/lib/docker error while building Docker ...
The error "too many links" usually means that there is a symbolic link pointing to itself, and is not specific to docker. To...
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
Ok, the pull request https://github.com/docker-java/docker-java/pull/1211 fixed the unit tests as mentioned before and I also added the many tests to increase coverage to cover the tar created and passed to the docker daemon. I will work on fixing the issue now.
The pull request is related to this bug because I fixed the units tests that now fails because symlink are not preserved. The only thing is the unit tests are testing CompressArchiveUtil.tar method which is not the method used when sending the docker build folder to docker daemon.
I will either add tests for CompressArchiveUtil.archiveTARFiles or rework both methods to remove the code duplication and then I will fix code to preserve symlinks.