figlio perduto
figlio perduto

Reputation: 170

Where is the file I mounted at run time to Docker?

I mounted my secret file secret.json at runtime to a local docker, and while it works, I don't seems to find this volume anywhere.

My docker file looks like this and has no reference to secret:

RUN mkdir ./app
ADD src/python ./app/src/python

ENTRYPOINT ["python"]

Then I ran

docker build -t {MY_IMAGE_NAME} .
docker run -t -v $PATH_TO_SECRET_FILE/:/secrets/secret.json  \
  -e MY_CREDENTIALS=/secrets/secret.json \
  {MY_IMAGE_NAME} ./app/src/python/runner.py

This runs successfully locally but when I do

docker run --entrypoint "ls" {MY_IMAGE_NAME}

I don't see the volume secrets.

Also, if I run

docker volume ls

it doesn't have anything that looks like secrets.

Without environment variable MY_CREDENTIALS the script won't run. So I am sure the secret file is mounted somewhere, but can't figure out where it is. Any idea?

Upvotes: 0

Views: 45

Answers (1)

Kārlis Ābele
Kārlis Ābele

Reputation: 1021

You are actually creating two separate containers with the commands you are running. The first docker run command creates a container from the image you have built with the volume mounted and then the second command creates a new container from the same image but without any volumes (as you don't define any in your command)

I'd suggest you give your container a name like so

docker run -t -v $PATH_TO_SECRET_FILE/:/secrets/secret.json  \
  -e MY_CREDENTIALS=/secrets/secret.json \
  --name my_container {MY_IMAGE_NAME} ./app/src/python/runner.py

and then run exec on that container

docker exec -it my_container sh

Upvotes: 3

Related Questions