Search code examples
dockerdocker-volume

Is it possible to save file from docker container to host directly


I have a container that runs a Python script in order to download a few big files from Amazon S3. The purpose of this container is just to download the files so I have them on my host machine. Because these files are needed by my app (which is running in a separate container with a different image), I bind mount from my host to the app's container the directory downloaded from the first container.

Note 1: I don't want to run the script directly from my host as it has various dependencies that I don't want to install on my host machine.

Note 2: I don't want to download the files while the app's image is being built as it takes too much time to rebuild the image when needed. I want to pass these files from outside and update them when needed.

Is there a way to make the first container to download those files directly to my host machine without downloading them first in the container and then copying them to the host as they take 2x the space needed before cleaning up the container?

Currently, the process is the following:

  1. Build the temporary container image and run it in order to download the models
  2. Copy the files from the container to the host
  3. Cleanup unneeded container and image

Note: If there is a way to download the files from the first container directly to the second and override them if they exist, it may work too.

Thanks!


Solution

  • You would use a host volume for this. E.g.

    docker run -v "$(pwd)/download:/data" your_image
    

    Would run your_image and anything written to /data inside the container would actually write to the host in the ./download directory.