Search code examples
dockerdocker-composedocker-machinedocker-for-windowsdocker-desktop

Moving a File from Machine to Container Docker


I'm having an issue with Docker right now (Windows 7) and would greatly appreciate any insight. I set up a container in docker named tf_files/starwars and wanted to put a file into this container but I get this error:

missing destination file operation after" C:\Users\Brian\Downloads\darthvader

I have tried adding quotation marks, but to no avail. I would greatly appreciate any help on this as I have been trying to figure out how to add this file from my computer to this container for several hours.


Solution

  • From what I know, to add a file into your container you can do this in 2 ways.

    You either pre-bake the file into the docker image by using the COPY syntax in your Dockerfile.

    See: https://docs.docker.com/engine/reference/builder/#copy

    Alternatively, you can mount the volume of your container to the host.

    Example: docker run -v c:\<path>:c:\<container path>

    Where c:\path will be the directory on your windows machine and container_path is the directory your container will see the files from your host machine.

    As such, whatever files you put in the C:\path area from your host, will also be visible within the container.

    See: https://docs.docker.com/engine/tutorials/dockervolumes/#mount-a-host-directory-as-a-data-volume