version: "3.8"
networks:
frontend:
backend:
services:
apache:
container_name: apache
build: ./docker/apache/
ports:
- "8001:80"
volumes:
- ./src:/usr/local/apache2/htdocs
networks:
- frontend
- backend
php:
container_name: php
build: ./docker/php
ports:
- "9001:9000"
volumes:
- ./src:/usr/local/apache2/htdocs
working_dir: /usr/local/apache2/htdocs
networks:
- backend
apache.conf
LoadModule deflate_module /usr/local/apache2/modules/mod_deflate.so
LoadModule proxy_module /usr/local/apache2/modules/mod_proxy.so
LoadModule proxy_fcgi_module /usr/local/apache2/modules/mod_proxy_fcgi.so
<VirtualHost *:80>
ProxyPassMatch ^/(.*.php(/.*)?)$ fcgi://php:9000/usr/local/apache2/htdocs/$1
DocumentRoot /usr/local/apache2/htdocs
<Directory /usr/local/apache2/htdocs/public>
Options -Indexes +FollowSymLinks
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
As you can see Project folder Directory. when try to access http://localhost:8002/ it’s not show public folder in browser index of.
When Change the Directory path in apache.conf File not found. error message is showing on browser
<Directory /usr/local/apache2/htdocs/public>
PHP Dockerfile
FROM php:8.1-fpm
COPY php.ini /usr/local/etc/php/conf.d/php.ini
RUN apt-get update
&& apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev libmcrypt-dev
&& docker-php-ext-install pdo
Apache Dockerfile
FROM httpd:2.4.51
COPY apache.conf /usr/local/apache2/conf/apache.conf
RUN echo "Include /usr/local/apache2/conf/apache.conf"
>> /usr/local/apache2/conf/httpd.conf
2
Answers
For testing, try instead the
--mount
syntax, with a full path as source, ondocker run
:It specifies a bind mount, which means a file or directory on the host machine is mounted into a container.
Check also the output of
docker inspect yourContainer
, in order to see what volume has been set up.Since all your other files are showing up it’s most likely a permissions issue. Your
public
directory is probably owned by theapache
orhttp
orwww-data
user on your host system and that user’suid
and/orgid
do not match what is being used inside the container. You can find out the ids of the host user like this…First, determine the right username :
Then get the
uid
of that user :And the
gid
:Finally, append the below lines to your apache
Dockerfile
, replacing theARG
values with the results of the above commands :The official
httpd
image that you are using runs as the userwww-data
so do not change that in theusermod
commands, we are just changing the ids of the existing user in the container to match your host system.To make this more flexible/portable you can also pass the values in from your compose file.
Alternatively
For a quick and dirty fix, just do
chmod -R a+r ./src/public
on the host. This will probably work but is less secure. However, if you are just testing things out or only setting up this project for personal use then this may be the easiest solution.