Laravel with docker on RPI - Failed to open stream: Permission denied

947 views Asked by At

I am testing deployment with docker on RPI but getting "Failed to open stream: Permission denied" I tried few solutions but none of them worked for me

Permission Denied Error using Laravel & Docker

Laravel & Docker: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied

my Dockerfile:

FROM php:8.0-fpm-alpine

RUN docker-php-ext-install pdo pdo_mysql
RUN chown -R www-data:www-data /var/www
RUN chmod -R 755 .

and docker-compose.yml

version: "3.7"
networks:
  laravel:

services:

  nginx:
    image: nginx:stable-alpine
    restart: unless-stopped
    container_name: nginx
    ports:
      - "80:80"
    volumes:
      - ./:/var/www/html
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - php
      - mariadb
    networks:
      - laravel

  mariadb:
    image: yobasystems/alpine-mariadb:latest
    restart: unless-stopped
    container_name: mariadb
    tty: true
    ports:
      - "4306:3306"
    volumes:
      - ./mariadb:/var/lib/mariadb
    environment:
      MYSQL_DATABASE: laravel
      MYSQL_ROOT_PASSWORD: laravel_dev
      MYSQL_USER: laravel_dev
      MYSQL_PASSWORD: laravel_dev
      SERVICE_TAGS: dev
      SERVICE_NAME: mariadb
    networks:
      - laravel

  phpmyadmin:
    image: phpmyadmin
    container_name: phpmyadmin
    restart: unless-stopped
    ports:
      - 4380:80
    environment:
        PMA_ARBITRARY: 1
        PMA_PORT: 3306
        PMA_HOST: mariadb
        PMA_USER: laravel_dev
        PMA_PASSWORD: laravel_dev
    depends_on:
      - mariadb
    networks:
      - laravel

  php:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: php
    volumes:
      - ./:/var/www/html
    ports:
      - "9000:9000"
    networks:
      - laravel

  composer:
    image: composer:latest
    container_name: composer
    volumes:
      - ./:/var/www/html
    working_dir: /var/www/html
    networks:
      - laravel

  npm:
    image: node:current-alpine3.14
    container_name: npm
    volumes:
      - ./:/var/www/html
    working_dir: /var/www/html
    entrypoint: ['npm']
    networks:
      - laravel

  artisan:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: artisan
    volumes:
      - ./:/var/www/html
    depends_on:
      - mariadb
    working_dir: /var/www/html
    entrypoint: ['php', '/var/www/html/artisan']
    networks:
      - laravel

Only thing that worked was chmod 777 on project root folder but that is not the solution i would be comfortable with using.

1

There are 1 answers

0
Yon On

So i found a solution on reddit https://www.reddit.com/r/docker/comments/hjsipd/permission_denied_with_volumes/fwoixqe/

I had to sign project folder to container user, which i found with less /etc/passwd. In this case name of user was www-data with UID 82. And command chown -R 82:82 .