Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel storage with Docker

I'm setting up Docker for a Laravel app which is an internal CDN with vast amount of images and other static files living in ./storage/app, both private and public. I want the Docker image to be built with GitLab CI and my question is what is the right way of building it without overriding the contents of the storage? Those contents aren't present in the repo.

I have two thoughts about that:

  • Create a symlink from /var/www/html to project's ./storage/app/public and a symlink from /some_other_folder to project's ./storage/app/private. In this case the question is can I write a file to a soft link of a folder and if I can, will the file really appear in the original folder of the symlink? If all of this is applicable, I am also interested if I can really create a symlink to a folder inside a Docker container...

  • Set up Laravel Storage to write files externally instead of the folders inside the folder. In this case, the question is how should I configure Laravel and Docker to allow files to be written outside the container, putting them right into /var/www/html for public and /some_other_folder for private?

Is either of the thoughts correct/good/even achievable? Or is there any other way of solving the problem?

like image 642
Sergey Orlov Avatar asked Jan 31 '18 01:01

Sergey Orlov


1 Answers

I know the question is by far not the most recent on, but since i had the same problem and did quite some research myself until i got an idea:

I've started the php container using two bind mounts that work like the link created by artisan would:

version: '3.7'

services:
  laravel:
    image: php
      volumes:
        - type: bind
          source: /path/to/laravel/project/
          target: /var/www/html/
        - type: bind
          source: /path/to/laravel/project/storage/app/public/
          target: /var/www/html/public/storage/
like image 52
jkreimei Avatar answered Oct 20 '22 03:10

jkreimei