I’m running into issues with file permissions when trying to run a Dockerized CodeIgniter 4 project on Windows using WSL2 and Docker Compose. The project worked fine on Docker Desktop, but when I tried moving it onto WSL2 for performance reasons I got a 403 Forbidden error.
Environment:
OS: Windows 10 with WSL2 (Ubuntu)
Docker: Docker Engine running inside WSL2
Application Framework: CodeIgniter 4
My docker-compose.yml:
services:
portal:
build: .
ports:
- "8001:80"
volumes:
- .:/var/www/html
My Dockerfile:
FROM php:8.1-apache
# Copy application files to the container
COPY . /var/www/html/
# Install dependencies
RUN apt-get update
&& apt-get install -y curl git unzip libpq-dev libicu-dev libzip-dev gnupg
zlib1g-dev g++ libpng-dev libonig-dev unixodbc-dev
&& curl -s https://getcomposer.org/installer > composer_installer.php &&
php composer_installer.php
&& mv composer.phar /usr/local/bin/composer &&
rm composer_installer.php
# Install SQL Server Drivers & Tools
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql18
&& ACCEPT_EULA=Y apt-get install -y mssql-tools18
&& echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc
source ~/.bashrc
# Enable extensions
RUN docker-php-ext-install pdo intl gd mbstring zip
&& pecl install sqlsrv pdo_sqlsrv
&& docker-php-ext-enable sqlsrv pdo_sqlsrv
&& apt-get update
&& apt-get install -y libxml2-dev
&& docker-php-ext-install soap
# Create folder cache and permissions
RUN mkdir -p writable/cache
RUN chown -R www-data:www-data writable/cache
&& chmod -R 775 writable/cache
# Configurando apache
RUN a2enmod rewrite
# Expose port 80 the container for web traffic
EXPOSE 80
I have uninstalled Docker Desktop, I’ve tried running it both inside the WSL2 filesystem itself and through the mnt but neither of those times it has worked.
When I tried accessing my ci4’s index through localhost:8001/public whilist building it from the mnt I got this error:
Fatal error: Uncaught ErrorException: chmod(): Operation not permitted in /var/www/html/vendor/codeigniter4/framework/system/Log/Handlers/FileHandler.php:121
T
After I copied my project’s files directly onto the WSL2 and tried to access the same link it seemingly worked, as I was redirected to another file(intentional), but that file had broken CSS and just generally wasn’t working properly.
I’ve tried changing permissions, adding in chown -R www-data:www-data . && chmod -R 775 . and it didn’t have any effect on the issue.
2
First of all, I can’t replicate your issue; therefore, I am not so sure what cause the permission issue.
However, I think it might related to file system integration between docker and WSL2. Therefore, you don’t have to uninstall docker desktop from your Windows system. Docker desktop itself has some integration setting for WSL2.
Here are some settings on docker desktop:
- Go “Settings” -> “General” -> Click up “Use the WSL 2 based engine (Windows Home can only run the WSL 2 backend)”
- Go “Settings” -> “Resources” -> “WSL integration” -> “Enable integration with my default WSL distro” -> Click up “Ubuntu22.04”