X Tutup
Skip to content

Error during image build when Dockerfile in subdirectory of build context #551

@osek666

Description

@osek666

Hello!

I try to build docker image with your library and think I found a bug.
I have such project structure:

/path/to/project/docker/Dockerfile
/path/to/project/target/app.jar

In my Dockerfile:

(...)
COPY target/app.jar /opt/app/app.jar
(...)

I try to build image with code:

final String baseDirectory = "/path/to/project";
final String dockerfile = baseDirectory + "/docker/Dockerfile";
dockerClient.buildImageCmd()
                .withBaseDirectory(new File(baseDirectory))
                .withDockerfile(new File(dockerfile))
                .exec()
                .awaitImageId();

I get error: Could not build image: lstat target/app.jar: no such file or directory

I think there is bug in class Dockerfile.
In method processAddStatement() is line

src = new File(dockerFolder, resource);

and dockerFolder is parent directory of Dockerfile. IMO it is incorrect, it should be

src = new File(baseDirectory, resource);

where baseDirectory is directory passed to method withBaseDirectory() of BuildImageCmd.

From command line build works with command

docker build -f docker/Dockerfile .

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup