Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Docker execute shell command in ADD instruction's src_path

I have a bunch of folders named 1/ 2/ 3/ in a directory which contains a dockerfile.
I’m trying to add the latest folder 3/ to the docker container using the docker add instruction in the dockerfile.

I came up with this ls -r | grep "[0-9]" | head -1 to give the folder with highest valued name. But I’m unable to execute it in the docker add instruction.

DOCKERFILE:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

FROM tensorflow/serving:2.8.0

WORKDIR /models

ADD ls -r | grep "[0-9]" | head -1 ./

ENV MODEL_NAME NumPlateDetector

ERROR:

ADD failed: file not found in build context or excluded by .dockerignore: stat ls: file does not exist

Any tips on how i can include that folder or get the ADD instruction to execute that line?

>Solution :

That feature does not exist, you will need to template your Dockerfile. For example:

# contents of "Dockerfile.template"

FROM tensorflow/serving:2.8.0

WORKDIR /models

ADD ${directory_to_add}

ENV MODEL_NAME NumPlateDetector

And then in a shell script:

export directory_to_add="$(ls -r | grep "[0-9]" | head -1 ./)"

envsubst < Dockerfile.template > Dockerfile

Reference to Dockerfile ADD instruction for completeness:

https://docs.docker.com/engine/reference/builder/#add

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading