0

I'm trying to pass a file to a docker container using the VOLUME instruction but cannot find a way to do it properly.

Right now I have the instruction inside my Dockerfile as:

...
VOLUME ~/.aws/credentials /home/app/.aws/credentials
...

, but it seems as docker instead of mounting the file creates an empty folder named credentials inside an .aws folder.

I also tried mounting it with:

VOLUME ~/.aws/credentials:/home/app/.aws/credentials

, but this actually does nothing. It doesn't even create the .aws folder.

I'm trying to do it that way so I don't have to add the -v flag when doing docker run.

From the documentation I could not find any valid way to do it that way. Does anyone have any proper solution to such case?

  • From the [docs](https://docs.docker.com/engine/reference/builder/#notes-about-specifying-volumes): "The VOLUME instruction does not support specifying a host-dir parameter. You must specify the mountpoint when you create or run the container." – Rafael-WO Nov 23 '21 at 09:30
  • Is there any workaround for that? I don't want to have it fixed inside the `docker run` command – This-is-patriiick Nov 23 '21 at 09:35
  • You _must_ put it in the `docker run` command, your `docker-compose.yml` file, or similar run-time configuration; there is no workaround. An image can't grant itself arbitrary access to host resources. – David Maze Nov 23 '21 at 10:53
  • 1
    (If you're on current Docker, and you need AWS credentials during the build, current Docker has a `RUN --mount` option, and the "how to mount host volumes during the build" question details this. In this context, also remember that AWS credentials could come from the EC2 metadata service or via the EKS OpenID Connect path, among other places, so that host file isn't necessarily right.) – David Maze Nov 23 '21 at 10:59

0 Answers0