I am working on an application. Using NodeJS for language and docker docker-compose for deployment.
I have an endpoint for uploading files. When i upload a file application keeps it at the "files" folder (files folder is at the root of the project). When container restarts i dont want to loose files, so i created a volume named "myfiles" and mounted it to "/files" path.
But when i check the myfiles volume path i dont see any of the created files by api. And if i restart the container uploaded files disappears.
Here is my docker-compose.yaml file for api
version: '3.1'
services:
api:
image: api-image
restart: always
volumes:
- myfiles:/files
volumes:
myfiles:
After docker-compose up -d
i upload some files and see them in container by calling
docker exec -it container_name ls
files node_modules package.json
index.js package-lock.json src
docker exec -it container_name ls files
d5a3455a39d8185153308332ca050ad8.png
Files created succesfully.
I checked if container mounts correctly by
docker inspect container_name
and result:
"Mounts": [
{
"Type": "bind",
"Source": "/var/lib/docker/volumes/myfiles/_data",
"Destination": "/files",
"Mode": "rw",
"RW": true,
"Propagation": "rslave"
}
]
You are creating volume, you are not using folder. Try to use folder myfiles
from current directory:
version: '3.1'
services:
api:
image: api-image
restart: always
volumes:
- ./myfiles:/files