Laravel, Nginx and Docker Container, Permission Denied - laravel

I have created a laravel project and put it in a docker container and it all seems to load fine, however at some point I get an error message saying:
There is no existing directory at "/Users/john/Documents/work/dashboard/src/storage/logs" and its not buildable: Permission denied
It is strange that Laravel is trying to write into a file or directory that is part of my local environment, instead of the docker container environment which I would expect to be something like:
/var/www/storage/logs
This is my docker-compose.yml:
version: '2'
services:
# The Web Server
web:
build:
context: ./
dockerfile: web.signup.dockerfile
working_dir: /var/www
volumes:
- ./src:/var/www
- /var/www/storage
env_file: 'src/.env'
ports:
- 80:80
volumes:
dbdata:
And this is my Dockerfile
FROM centos:latest
RUN set -ex \
&& yum install -y epel-release \
&& yum update -y mysql-client libmagickwand-dev \
&& yum install -y libmcrypt-devel \
&& yum install -y python-pip \
&& pip install --upgrade pip \
&& yum install -y zip unzip \
&& yum install -y java-1.8.0-openjdk \
&& yum clean all
RUN pip install --upgrade --ignore-installed six awscli
RUN yum install -y supervisor
RUN yum install -y php-pear php-devel
RUN pecl install imagick
# Add the Ngix
ADD nginx.repo /etc/yum.repos.d/nginx.repo
# Add the Centos PHP dependent repository
RUN rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
RUN yum update -y
# Installing Nginx
RUN yum -y install nginx
# Installing PHP
RUN yum -y --enablerepo=remi,remi-php72 install php-fpm php-common php-mcrypt php-mbstring
WORKDIR /var/www
ADD vhost.prod.conf /etc/nginx/conf.d/default.conf
COPY src/. /var/www
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \
&& php composer-setup.php \
&& php -r "unlink('composer-setup.php');" \
&& php composer.phar install --no-dev --no-scripts \
&& rm composer.phar
RUN chown -R apache:apache \
/var/www/storage \
/var/www/bootstrap/cache
EXPOSE 80
EXPOSE 9000
RUN mkdir -p /run/php-fpm
COPY supervisord.conf /supervisord.conf
CMD ["/usr/bin/supervisord", "-c", "/supervisord.conf"]
Any ideas at all?

Works as designed,
you are mounting "src" from your current directory into the container.
volumes:
- ./src:/var/www
If you want to access your code inside the container you could add the files while building.
To fix your "bug",
chmod -R 777 /Users/john/Documents/work/dashboard/src/storage/logs
Would be ok a for local development environment

From my end, results are when no matter what folder permission we changed in the physical folder.
Delete everything in bootstrap/cache/* solved the issue.

In my case, I got this error when I ran out of HDD space and I cleared it
Only this helped:
rm bootstrap/cache/config.php
php artisan cache:clear
composer dump-autoload

Related

When Deploying CDK to AWS via Docker, bash: cdk: command not found

Present are two files, Dockerfile.infra and docker-compose-infra.yml. Firstly, docker-compose-infra.yml is built via the following command:
docker-compose --file docker-compose-infra.yml build
This results in no errors and finishes as expected.
The problem arises when trying to deploy this to AWS. The following command:
docker-compose --file docker-compose-infra.yml run cdk
Produces this error:
bash: cdk: command not found
This appears to be triggered when the docker-compose-infra.yml attempts to run the cdk deploy bash command.
The command should run because within the Dockerfile.infra build, cdk is installed via npm install -g aws-cdk-lib.
Dockerfile.infra file:
FROM node:16-slim
ENV DEBIAN_FRONTEND=noninteractive
RUN npm install -g aws-cdk-lib \
&& apt-get update -y \
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends \
# install Python
python3-pip \
# install Poetry via curl
curl \
&& curl -k https://install.python-poetry.org | python3 - \
&& apt-get remove curl -y \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/*
COPY pyproject.toml poetry.lock /
ENV PATH=/root/.local/bin:$PATH
RUN poetry config virtualenvs.create false \
&& poetry install --no-dev
WORKDIR /app/
COPY app.py cdk.json cdk.context.json /app/
COPY stacks/ /app/stacks/
docker-compose-infra.yml:
version: "3"
services:
cdk:
command: bash -c "cdk deploy --require-approval never --all --parameters my-app-${ENVIRONMENT}-service:MyServiceImageTag=${IMAGE_TAG}"
build:
context: ./
dockerfile: Dockerfile.infra
environment:
- AWS_PROFILE=${AWS_PROFILE}
- ENVIRONMENT=${ENVIRONMENT}
- DEPLOY_ACCOUNT=${DEPLOY_ACCOUNT}
volumes:
- ~/.aws/credentials:/root/.aws/credentials
You need to install aws-cdk not aws-cdk-lib
RUN npm install -g aws-cdk \
This might be a bit confusing because aws-cdk-lib is also the name of the required Python dependency when writing Python CDK apps and a valid npm package.

Docker-compose up missing files

My question is simple , when docker-compose build : some new folders will be generated using npm run prod command , I've added in my Dockerfile "ls -lhtr the_missingFolder" and I can see it's there.
After complete building I ran docker-compose up >> Boomm the folder not in the container , why ?
How can I fix that please.
FROM ubuntu:16.04
RUN apt-get update && apt install -y build-essential
RUN apt-get update -y && apt-get install -y openssl zip unzip git libpng-dev zlib1g-dev libicu-dev libtool g++
RUN apt-get update && apt-get install -y --no-install-recommends apt-utils
RUN apt install -y composer
RUN apt-get install -y curl wget
RUN apt-get install -y autoconf automake pkg-config libgtk-3-dev nasm
RUN apt-get clean && apt-get update && apt-get install -y locales
RUN locale-gen en_US en_US.UTF-8
RUN apt-get install -y python-software-properties
RUN apt-get install -y software-properties-common
RUN LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php
RUN apt-get update
RUN apt install -y php7.1-fpm php7.1-mbstring php7.1-xmlrpc php7.1-soap
php7.1-gd php7.1-xml php7.1-cli php7.1-zip php7.1-pgsql php7.1-curl
RUN curl -sL https://deb.nodesource.com/setup_11.x | bash -
RUN apt-get install -y nodejs
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . ./
COPY package*.json ./
RUN cp .env.docker .env
RUN npm install
RUN npm run prod
COPY . /usr/src/app/
WORKDIR /usr/src/app
RUN composer update
RUN composer install --no-interaction --prefer-dist --optimize-autoloader
RUN php artisan config:clear
RUN php artisan optimize
CMD bash -c "php artisan db:seed --class=App\\module\\role\\database\\seed\\role"
CMD bash -c "php artisan db:seed --class=App\\module\\notification\\database\\seed\\notification"
CMD bash -c "php artisan notifications:generate-files"
CMD bash -c "php artisan migrate"
CMD bash -c "composer install && php artisan serve --host=0.0.0.0 --port=8000"
EXPOSE 8000
Best regards
I had this problem before. In my case, I had a named volume that gets reused every time docker-compose up is ran.
I just destroyed the volume along with the containers using -v option in docker-compose down and everything is there the next time I ran docker-compose up.

E: Package 'mysql-client' has no installation candidate in php-fpm image build using docker compose

Im fairly new to docker and so im trying to learn more about it using a laravel project, im following this tutorial:
https://www.digitalocean.com/community/tutorials/how-to-set-up-laravel-nginx-and-mysql-with-docker-compose
Ive adjusted the Dockerfile a bit from what the tutorial has but even the tutorial file causes the same result.
FROM php:7.3-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Install dependencies
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - && \
apt-get update && apt-get install -y mysql-client \
RUN npm install -g npm
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo pdo_mysql
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
# Copy existing application directory contents
COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www
# Change current user to www
USER www
# Set working directory
WORKDIR /var/www
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
But i keep getting the following error when i run docker-compose up -d:
E: Package 'mysql-client' has no installation candidate
ERROR: Service 'app' failed to build: The command '/bin/sh -c curl -sL https://deb.nodesource.com/setup_10.x | bash - && apt-get update && apt-get install -y mysql-client nodejs build-essential vim git curl' returned a non-zero code: 100
Am i missing something?
I expected this to work since i am running apt-get update before installing mysql-client.
Thanks.
php:7.3-fpm now use Debian 10 (Buster) as its base image and Buster ships with MariaDB, so just replace mysql-client with mariadb-client should fix it.
If you still want to use the mysql client, it's called default-mysql-client now.
php:7.2-apache triggers the error as well, but I resolve it using php:7.2.18-apache
it worked for me: sudo apt-get update && apt-get install -y git curl libmcrypt-dev default-mysql-client
or alternatively apt-cache search mysql-server
find out your servers then sudo apt-get install default-mysql-server default-mysql-server-core mariadb-server-10.6 mariadb-server-core-10.6
in my case it was the above codes

Dockerfile does not create files and folders in Laravel

I have a Laravel Project and I created a docker-compose and dockerfile.
I do docker-compose build and my problem is that:
It does not create the folder vendor (composer install).
Do not copy .env.local to .env
Do not create the node_modules folder
docker-compose.yml
version: "3"
services:
api:
container_name: nadal_api
build:
context: .
dockerfile: Dockerfile
volumes:
- .:/var/www/html/app
ports:
- 5002:80
DockerFile
FROM composer:latest AS composer
#Generamos el primer build desde un container de nodejs
FROM node:latest as nodebuild
COPY --chown=root:www-data . /var/www/html/app
WORKDIR /var/www/html/app
RUN npm install
RUN npm run production
#Tomamos la imagen de php fpm para utilizar las librerias compiladas
FROM php:7.2-fpm-stretch
#Instalamos nginx y otras dependencias del framework
RUN apt-get update && apt-get install -y \
apt-transport-https \
wget \
lsb-release \
libxml2-dev \
nginx \
ca-certificates \
git \
zip
#Compilamos pgsql
RUN apt-get install -y libpq-dev \
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
&& docker-php-ext-install pdo pdo_pgsql pgsql
#Compilamos las librerias requeridas por laravel
RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-install xml
RUN docker-php-ext-install mbstring
#Install supervisor porque debemos tener dos procesos, nginx y fpm
RUN wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
RUN echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list
RUN apt-get update && apt-get install -y \
supervisor \
curl \
libssl-dev \
libmcrypt-dev
#Copiamos las configuraciones de nginx, el host y supervisor
ADD docker/nginx.conf /etc/nginx/nginx.conf
ADD docker/virtualhost.conf /etc/nginx/conf.d/default.conf
ADD docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
#Copiamos el projecto con los modulos de node y los assets compilados
COPY --from=nodebuild --chown=root:www-data /var/www/html/app /var/www/html/app
COPY --chown=root:www-data ./.env.local /var/www/html/app/.env
#Aplicamos los permisos que corresponden
RUN chmod -R g+w /var/www/html/app/storage
RUN chmod -R g+w /var/www/html/app/bootstrap
#Copiamos composer
COPY --from=composer /usr/bin/composer /usr/bin/composer
##Download composer packages
WORKDIR /var/www/html/app
RUN composer install
RUN chmod -R g+w /var/www/html/app/vendor
RUN php artisan key:generate
EXPOSE 80
CMD ["/usr/bin/supervisord"]
Can it be the permissions?
Step 21/30 : COPY --chown=root:www-data ./.env.${environment:-local}
/var/www/html/app/.env ---> 7d1038fe2615
Step 26/30 : RUN composer install ---> Running in 8e3265277308
Removing intermediate container 8e3265277308 ---> 429553e893a4 Step
27/30 :
RUN chmod -R g+w /var/www/html/app/vendor ---> Running in
9e276059478b Removing intermediate container 9e276059478b --->
d52ee5ad4ec4
When building the image, you COPY your whole current directory to /var/www/html/app, then stuff happens with the content there. On docker-compose up, you mount your whole folder again at this destination, which overwrites everything that happened on docker-compose build. To avoid this, just remove the volumes part from your docker-compose.yml.

ADD command not working Docker

FROM phusion/baseimage:0.9.16
MAINTAINER Raheel <raheelwp#gmail.com>
RUN apt-get update
RUN apt-get -y install apache2 libapache2-mod-php5 curl git
RUN add-apt-repository ppa:ondrej/php5-5.6
RUN apt-get update
RUN apt-get -y install python-software-properties
RUN apt-get update
RUN apt-get -y --force-yes install php5 php5-cli php5-mcrypt php5-curl php5-xdebug php5-json
RUN apt-get clean
RUN php5enmod mcrypt
RUN rm -rf /var/www/html
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf
ADD /home/raheel/code/laravel-app /var/www/laravel-app
EXPOSE 80
COPY setup-laravel.sh /var/www/laravel-app/setup-laravel.sh
RUN ["chmod", "+x", "/var/www/laravel-app/setup-laravel.sh"]
ENTRYPOINT ["/var/www/laravel-app/setup-laravel.sh"]
I created the above Dockerfile to run laravel application.
Then i ran docker build -t raheelwp/laravel-app . command and it created the image without name. Then i ran docker tag imageid raheelwp/laravel-app . After this when i check docker images it shows my image with name.
So far so good. But when i run docker run -t raheelwp/laravel-app and then login into container by docker exec -it containerid bash and do the ls on /var/www directory there is no laravel-app folder present there.
I am new to docker and this is my first ever docker file. I would be very thankful to you to please guide me why i am having this problem and how to fix this.
Thanks

Resources