I’m beginning with Docker, first message here.
I’m trying to create a LAMP image that I could use on several computer.
After some research, I’ve got a Debian LAMP server functionnal. But I have some questions. How could I have more than 1 virtualhost ? How modify the security.conf file (for ServerToken and signature) ?
If you have some suggestion about my files, I appreciate, thanks a lot.
Here’s the Dockerfile for Apache :
FROM httpd:2.4.38
RUN apt-get update;
COPY demo.apache.conf /usr/local/apache2/conf/demo.apache.conf
RUN echo "Include /usr/local/apache2/conf/demo.apache.conf" \
>> /usr/local/apache2/conf/httpd.conf
COPY security.conf /etc/apache2/conf-enabled/
The file demo.apache.conf
ServerName localhost
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>
# Proxy .php requests to port 9000 of the php-fpm container
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://php:9000/var/www/html/$1
DocumentRoot /var/www/html/
<Directory /var/www/html/>
DirectoryIndex index.php
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# Send apache logs to stdout and stderr
#CustomLog /proc/self/fd/1 common
#ErrorLog /proc/self/fd/2
CustomLog /var/log/apache2/access.log combined
ErrorLog /var/log/apache2/error.log
</VirtualHost>
The Dockerfile for PHP and Debian
FROM php:7.3.1-fpm-stretch
RUN apt-get update;
RUN docker-php-ext-install mysqli
COPY php.ini /usr/local/etc/php/php.ini
The first thing you should start understanding is that a container is NOT a host. If I was setting up multiple websites using the LAMP-stack, I would actually create them as different services/stacks. If needed, I would mount the different data volumes needed into the same base image but creating multiple containers.
If you do need multiple virtual hosts, you just need to create your own apache.conf and add it either when you build your image or when you start your container.
Don’t know if it helps you but this moment I stumbled over this interesting video by Bret Fisher that discusses the question whether you should run different vhosts in individual containers or all in a single one. “…using different Apache configs for each website. To me that’s old school, that’s pre-container.”
In my dockerfile, I can’t put a2enmod rewrite, command not found. The same thing if I tried to set the locales on fr_FR with locale-gen, and also for this : CMD /usr/sbin/apache2ctl -D FOREGROUND
What’s wrong with my files, I don’t understand what’s happening…
A little help please ?
Time to for you to debug.
After your build fails, you need to run a container and bring up a command shell from the most recent docker image displayed in a docker image ls command. You can then “snoop” around and try and locate the “missing” commands. If they are not found, you will need to install them, if you find them then you will need to specify the full path in your Dockerfile.
Check out this post. I provided detailed instructions to another person who had a similar problem.
a2enmod is a Debian-specific command and not available in the httpd image. If you want to use the rewrite module, you have to uncomment the following line in /usr/local/apache2/conf/httpd.conf:
#LoadModule rewrite_module modules/mod_rewrite.so
You find an example in the description of the httpd image under SSL/HTTPS that shows how to achieve this using sed.
There is quite a difference between the httpd image and what you know from Debian/Ubuntu.