I have the following docker-compose file:
version: "3.1"
services:
www:
build:
context: .
dockerfile: Dockerfile.lamp
ports:
- "${WEBSERVER_PORT}:80"
volumes:
- ./www:/var/www/html/
As you can see, the www folder in the same folder as the docker-compose.yml file is where the web code is hosted.
I have the following dockerfile (Dockerfile.lamp):
FROM php:8.1-apache
RUN a2enmod rewrite
RUN docker-php-ext-install pdo pdo_mysql
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
libicu-dev \
zlib1g-dev \
g++\
libpq-dev \
libmcrypt-dev \
git \
zip \
unzip
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql
RUN docker-php-ext-install mysqli
RUN docker-php-ext-configure intl \
&& docker-php-ext-install intl
All of it works, but one issue arose that in the www/index.php file I wrote
mkdir("testFolder", 0775, true);
giving me:
Warning: mkdir(): Permission denied in /var/www/html/index.php on line 1
Neither does mkdir("testFolder"); work
I tried adding the following line to the Docker.lamp file, without success:
RUN chown -R www-data:www-data /var/www
What can I Do?
I already checked:
- Permission Denied for mkdir() php in Docker
- Cannot create directory. Permission denied inside docker container
My Answer:
Docker-compose is a tool that allows you to define and run multi-container Docker applications. It uses a YAML file to configure the services, networks, and volumes needed for your application to run. With docker-compose, you can easily manage and orchestrate multiple Docker containers as a single application, making it easier to deploy and scale your applications.
Rate this post
3 of 5 based on 3471 votesComments