user4292309
user4292309

Reputation:

Adding files to docker container based on a docker-compose Environment variables

I have a large set of test files (3.2 gb) that I only want to add to the container if an environment variable (DEBUG) is set. For testing locally I set these in a docker-compose file.

So far, I've added the test data folder to a .dockerignore file and tried the solution mentioned here in my Dockerfile without any success.

I've also tried running the cp command from within a run_app.sh which i call in my docker file:

cp local/folder app/testdata

but get cp: cannot stat 'local/folder': No such file or directory, i guess because it's trying to find a folder that exists on my local machine inside the container?

This is my docker file:

RUN mkdir /app
WORKDIR /app
ADD . /app/

ARG DEBUG
RUN if [ "x$DEBUG" = "True" ] ; echo "Argument not provided" ; echo "Argument is $arg" ; fi

RUN pip install -r requirements.txt 
USER nobody

ENV PORT 5000
EXPOSE ${PORT}

CMD /uus/run_app.sh

Upvotes: 1

Views: 524

Answers (1)

David Maze
David Maze

Reputation: 160002

If it's really just for testing, and it's in a clearly named isolated directory like testdata, you can inject it using a bind mount.

Remove the ARG DEBUG and the build-time option to copy the content into the image. When you run the container, run it with

docker run \
  -v $PWD/local/folder:/app/testdata:ro \
  ...

This makes that host folder appear in that container directory, read-only so you don't accidentally overwrite the test data for later runs.

Note that this hides whatever was in the image on that path before; hence the "if it's in a separate directory, then..." disclaimer.

Upvotes: 0

Related Questions