Home > Blockchain >  Docker execute shell command in ADD instruction's src_path
Docker execute shell command in ADD instruction's src_path

Time:07-29

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:

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?

CodePudding user response:

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

  • Related