Laravel storage with Docker
Asked Answered
F

2

9

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?

Fachan answered 31/1, 2018 at 1:5 Comment(1)
docs.docker.com/engine/admin/volumes/volumesSensorimotor
E
12

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/
Exoteric answered 2/5, 2019 at 13:35 Comment(0)
S
-1

Try this:

docker exec -it my_container bash -c "cd public && ln -s ../storage/app/public storage"
Scraggy answered 20/4, 2021 at 20:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.