I have created a php fpm containers which is associated to the host user, in this way I doesn't have any issues with the file generated within the docker container (eg: when using php artisan make:controller
).
So I have this docker-compose.yml
:
version: '3.9'
services:
laravel-fpm:
user: 1000
container_name: laravel_app
restart: always
build:
context: .
dockerfile: ./docker/php-fpm/Dockerfile
volumes:
- ./src:/var/www/html
and this is the Dockerfile
:
FROM php:8.0.2-fpm-alpine
WORKDIR /var/www/html
RUN docker-php-ext-install pdo_mysql
RUN docker-php-ext-install mysqli
RUN apk add icu-dev
# Installa nodejs per l'utilizzo delle dipendenze npm
RUN apk add --update npm
RUN npm install gulp-cli -g
RUN npm install
CMD ["php-fpm"]
EXPOSE 9000
When I access within the container docker-exec -it laravel_app sh
, and then I run npm install
I get:
Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR!
npm ERR! To permanently fix this problem, please run:
npm ERR! sudo chown -R 1000:0 "/.npm"
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /.npm
npm ERR! errno -13
This problem is related to the USER
directive which I have specified on the container, is there a way to fix that?