I made a Docker image for my Laravel project. If I create a container for this it works fine. However if my image is updated I need to replace the container. After that the upload data and files in my storage/app/public folder are lost.
That is an undesirable effect. I do want to refresh the entire laravel project when I replace my container with a new version. But I want the upload data of users to remain in the storage/app/public folder.
According to Docker, the solution to this is to create a volume. Because the data will then be saved in the volume. Even if the container is refreshed.
How do I create a volume specific for the storage folder in the Laravel project?
Add this to the php service in your docker-compose.yml file.
This will map the current directory (where the docker-compose.yml is located) to /app in the container. Change the path on the left side of the : if its the wrong path
Some additional context. I have an Ubuntu development server. Here I am creating a Docker image via docker build. I push this image to Docker hub.
Then I have another server. A Windows server. Here I do a pull to get the new image. I delete the old container. I'm starting a new container for the latest image.
After that I lost my storage data on the Windows Server.
@Propolis Ok strange. I dont use windows so I am not sure how that works there. I recreate my containers quite often, and have never had a loss of storage data. But you can try and be more explicit with the storage directory perhaps?
Yes correct. The laravel application needs to be distributed to different OS environments. I'm now working on a windows server. But Ubuntu servers also follow.
I think I found a solution. I can also specify a volume when I run the "docker run" command. Via the parameter:
-v app_storage:/var/www/storage/app
Now a named volume has been succesfully created. I thought I could achieve the same effect via yml. But via command line when starting the container is also workable for me.