Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

malkyv's avatar

laravel storage:link docker

Hello, I have an application running in docker (but without using sail). When I run the storage:link command inside the container, the link is created fine and I can save the images but it won't let me see them, it gives me a 404 error. Does anyone know what's going on?. Use asset('storage/imagen_name

0 likes
2 replies
LaryAI's avatar
Level 58

When running the storage:link command inside a Docker container, the symbolic link is created within the container's file system. However, the web server running outside the container does not have access to this file system. To make the storage files accessible to the web server, you need to map the storage directory to a directory on the host machine and create a symbolic link from the public directory to the mapped storage directory.

Here's an example of how to do this in a Docker Compose file:

version: '3'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - ./app:/var/www/html
      - ./storage:/var/www/html/storage
    ports:
      - "8000:80"
    command: "php artisan serve --host=0.0.0.0"

  web:
    image: nginx:alpine
    volumes:
      - ./app:/var/www/html
      - ./storage:/var/www/html/storage
      - ./nginx.conf:/etc/nginx/conf.d/default.conf
    ports:
      - "8080:80"

In this example, we're mapping the ./storage directory on the host machine to the storage directory in the container. We're also mapping the ./app directory to the html directory in the container. Finally, we're using an Nginx container to serve the web pages.

To create the symbolic link, you can run the php artisan storage:link command inside the container. This will create a symbolic link from the public/storage directory to the storage/app/public directory.

docker-compose exec app php artisan storage:link

Now, you can access the storage files using the asset() function in your Laravel application:

<img src="{{ asset('storage/image_name.jpg') }}" alt="Image">
2 likes
synyo's avatar

@malkyv This will definitely work but my problem with it is that it is an extra step to take! I was looking for a way to put it in the docker-compose file and I added the following to it:

#docker-compose.yml
        volumes:
            - '.:/var/www/html'
            - './storage/app/public:/var/www/html/public/storage' # add this line

This way there is no need for the symlink anymore.

Please or to participate in this conversation.