dockerfile-plus icon indicating copy to clipboard operation
dockerfile-plus copied to clipboard

including from a top level directory

Open Mihai-P opened this issue 3 years ago • 2 comments

This looks very interesting, exactly what I was looking for to save me duplicating hundreds of line of code. Is it possible to include something in another directory? For example

INCLUDE+ ../Dockerfile.common

This would go 1 level up and get the file from there?

I tried it and I got this

failed to solve with frontend dockerfile.v0: failed to solve with frontend gateway.v0: rpc error: code = Code(128) desc = Could not read file " ../Dockerfile.common". Remember that the file path is relative to the build context, not the Dockerfile path.

I am running the docker-build command from the same directory as the Dockerfile.

If I move Dockerfile.common in the same directory it works just fine.

Mihai-P avatar Jul 05 '21 12:07 Mihai-P

same problem for me, any solution yet ?

grimpows avatar Apr 23 '22 10:04 grimpows

well i have sucessfully loaded a .common from other folder than the dockerfile folder first i should say that the "../" look like buggy so to avoid the prob of using "../" in the INCLUDE+ path i did like this :

in the docker-compose or with docker command specify the context path (that should be the parent folder of your project, where all your dockerfiles AND commons requirements are stored)

you can use ../ or so, note that the context is relative to where you launch the docker command (personnaly i'm using a bash script to launch docker-compose commands)

//docker-compose file version: '3.8' services: apache-php: build: context : ../../parent_folder_name_of_project

then specify the dockerfile that will be relative to the path given from context.

//docker-compose file version: '3.8' services: apache-php: build: context : ../../parent_folder_name_of_project/ dockerfile: sub_folder/another_sub_folder/Dockerfile

with that exemple your docker file should located at "../../parent_folder_name_of_project/sub_folder/another_sub_folder/Dockerfile"

suposing now that you have some commons file that you want include inside your dockerfile with the INCLUDE+

you can now use path that start from the context path given.

//dockerfile exemple ARG PHP_VERSION="" FROM php:${PHP_VERSION}-apache

INCLUDE+ alpine/php/commons/Dockerfile.cakephp_requirements.common

the include will work, and load the common from "CONTEXT_FOLDER_SPECIFIED_IN_COMPOSE/alpine/php/commons/Dockerfile.cakephp_requirements.common"

grimpows avatar Apr 23 '22 11:04 grimpows