MortenMoulder
MortenMoulder

Reputation: 6646

Equivalent of -v in the Dockerfile?

So I want to mount my Docker container on my Windows PC using a Dockerfile. So far I have been able to do this using the following command:

docker run -v %userprofile%\mounted-docker\:/tmp/ container-name

This would mount /tmp/ from my Docker container into my C:\Users\USERNAME\mounted-docker\ folder. However, I can't seem to find the equivalent instruction in the Dockerfile documentation.

The only documentation is probably VOLUME in the Dockerfile documentation, which specifies:

Volumes on Windows-based containers: When using Windows-based containers, the destination of a volume inside the container must be one of:

a non-existing or empty directory
a drive other than C:

That's fine and all... but how exactly do I specify that? Let's say I want to mount either / or /tmp/ in a specified folder or drive, how do I do that?

Upvotes: 0

Views: 545

Answers (1)

BMitch
BMitch

Reputation: 264571

The Dockerfile is used to build the image. To define how you'd like to run that image, you'll want to use a docker-compose.yml file.

In a Dockerfile, you cannot specify where a volume will be mounted from in the host. Doing so would open up docker to malicious image exploits where images from the Docker hub could mount the root filesystem and send private content to remote locations, or even perform a ransomware exploit. Specifying what elevated access a container can have is left up to the user running the image, from docker run or with the docker-compose.yml file.

Upvotes: 1

Related Questions