Skip to content

Nesting several Dockerfiles using Relative FROM breaks relative paths #13

@Akkyma232

Description

@Akkyma232

Hi!

Thank you for this project.
I have problems when I try to separate my build to several stages using Relative FROM. It seems like that this feature cause relative path corruption when there are more than one Relative FROM in dockerfiles chain

How to reproduce

Project structure:

├── dockerfiles
│   ├── Dockerfile.stage1
│   ├── Dockerfile.stage2
│   └── Dockerfile.stage3
├── file1.txt
├── file2.txt
└── file3.txt

Dockerfile.stage1:

FROM alpine

COPY file1.txt ./

Dockerfile.stage2:

#syntax = devthefuture/dockerfile-x

FROM ./dockerfiles/Dockerfile.stage1

COPY file2.txt ./

Dockerfile.stage3:

#syntax = devthefuture/dockerfile-x

FROM ./dockerfiles/Dockerfile.stage2

COPY file3.txt ./

Execute:

When I run stage1 and stage2 builds it works fine:
docker build -f dockerfiles/Dockerfile.stage1 .
docker build -f dockerfiles/Dockerfile.stage2 .

But stage3 build exits with error:
docker build -f dockerfiles/Dockerfile.stage3 .

Output:

[+] Building 1.8s (8/8) FINISHED                                                                                                                                                             docker:default
 => [internal] load build definition from Dockerfile.stage3                                                                                                                                            0.0s
 => => transferring dockerfile: 137B                                                                                                                                                                   0.0s
 => resolve image config for docker.io/devthefuture/dockerfile-x:latest                                                                                                                                1.3s
 => [auth] devthefuture/dockerfile-x:pull token for registry-1.docker.io                                                                                                                               0.0s
 => CACHED docker-image://docker.io/devthefuture/dockerfile-x:latest@sha256:2fbc2fe8ae7f7e29d6c419b92775ca0596a866de86a8c74f3c652b77f893ce6e                                                           0.0s
 => local://dockerfile (Dockerfile.stage3)                                                                                                                                                             0.0s
 => => transferring dockerfile: 38B                                                                                                                                                                    0.0s
 => local://context (dockerfiles/Dockerfile.stage2)                                                                                                                                                    0.0s
 => => transferring context: 184B                                                                                                                                                                      0.0s
 => local://context (dockerfiles/dockerfiles/Dockerfile.stage1)                                                                                                                                        0.0s
 => => transferring context: 2B                                                                                                                                                                        0.0s
 => local://context (dockerfiles/dockerfiles/Dockerfile.stage1.dockerfile)                                                                                                                             0.0s
 => => transferring context: 2B                                                                                                                                                                        0.0s
Dockerfile.stage3:1
--------------------
   1 | >>> #syntax = devthefuture/dockerfile-x
   2 |     
   3 |     FROM ./dockerfiles/Dockerfile.stage2
--------------------
ERROR: failed to solve: failed to execute dockerfile-x: failed to read dockerfile 'dockerfiles/dockerfiles/Dockerfile.stage1.dockerfile': open dockerfiles/dockerfiles/Dockerfile.stage1.dockerfile: no such file or directory
, Output: 

Problem

Seems like first Relative FROM in chain change cwd for next Relative FROMs

Expected behaviour:

Relative FROM always works relative to build context

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