Skip to content

Build command fails when symlinks in docker folder are used #532

@dvbobrov

Description

@dvbobrov

My 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);
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions