I try to make a simple file upload server. I wonder if it stores the uploaded file in a ram or hard disk since the container itself run as a virtual-machine in ram so it should not be able to have access to the disk right? unless I specify the bind-mounted volume option. So if the user upload a lot of files to the server at some points it's going to crash since it doesn't have ram space to store the files.
CodePudding user response:
Docker containers are isolated environments that run in memory. By default, any data that is created or modified inside a Docker container is not persisted when the container is stopped or removed. This means that if you upload a file to a Docker container, it will only be stored in the container's memory and will be lost when the container is stopped or removed.
However, Docker provides a way to persist data created or modified inside a container. This is done using Docker volumes. A Docker volume is a persistent storage location that is outside of the container's filesystem and can be shared or reused across containers.
When you create a Docker container, you can use the -v or --volume flag to specify a volume for the container to use. For example, you can use the following command to create a Docker container and mount the host machine's /tmp directory as a volume for the container:
docker run -d -v /tmp:/tmp <image>
If you want to store the uploaded files in a Docker volume, you can mount a volume when you create the container and specify a directory inside the volume as the destination for the uploaded files. This way, the files will be persisted in the volume and will not be lost when the container is stopped or removed.
CodePudding user response:
This heavily depends on the implementation of the program inside the container. If the program stores documents in memory, they'll be in memory in a container too; if it does a streaming upload to external storage, it will work that way in a container; if it stores the documents on disk, they'll be stored on disk in a container.
It is true that, without any mounted storage, the container filesystem is temporary, and anything you write there will be lost when the container exits. It is stored on disk, however, unless you specifically set up a RAM disk mount. The program should use more or less the same amount of memory in a container or not.