I am building a PHP Apache Web Service Docker Container Prototype.
- The first and simplest way was to create a Container with the official Image published by WordPress
with a simpleDockerfile
like:
FROM wordpress:latest
Which builds but than fails to run:
# docker run -it wordpress_local apache2-foreground
WordPress not found in /var/www/html - copying now...
Complete! WordPress has been successfully copied to /var/www/html
AH00534: apache2: Configuration error: No MPM loaded.
which is a Known Error unable to be fixed. So the Image is broken.
Other Images like php7-apache2
also produce the same Error.
- Unable to find a prebuild Image that would actually run I started to build an Image from scratch. It contains
- Alpine Linux 3.12
- Apache 2.4
- PHP 7.3
with the Dockerfile
:
# cat Dockerfile
FROM alpine:3.12
RUN apk add apache2 php7 php7-apache2
ADD html/ /var/www/html/
WORKDIR /var/www/html/
CMD ["httpd", "-DNO_DETACH -DFOREGROUND -e debug"]
and a docker-compose.yml
:
# cat docker-compose.yml
version: '3'
services:
web:
image: php_web_alpine
build: .
ports:
- "8081:8081"
This builds nicely:
# docker build -t php_web_alpine .
Sending build context to Docker daemon 7.68 kB
Step 1/5 : FROM alpine:3.12
---> a24bb4013296
Step 2/5 : RUN apk add apache2 php7 php7-apache2
---> Using cache
---> bf59e0c43f1f
Step 3/5 : ADD html/ /var/www/html/
---> 0fe4bfd871b2
Removing intermediate container cec9de242174
Step 4/5 : WORKDIR /var/www/html/
---> 03d3fe0a077f
Removing intermediate container b1763eb3e56b
Step 5/5 : CMD httpd -DNO_DETACH -DFOREGROUND -e debug
---> Running in 4ca69abc9f52
---> e3a33ae6e028
Removing intermediate container 4ca69abc9f52
Successfully built e3a33ae6e028
But than does not run because of a simple Configuration Error:
# docker-compose up
Recreating phpalpine_web_1 ... done
Attaching to phpalpine_web_1
web_1 | AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.20.0.2. Set the 'ServerName' directive globally to suppress this message
phpalpine_web_1 exited with code 0
It needs just to fill the httpd.conf
Configuration File with the correct values.
So, how can I fill the Web Service Configuration Files (Apache and PHP and others, etc ...) at Build Time to get a nice reproducible Build ?
Nothing could be more easy, add the COPY directive to your Dockerfile.
it will look like something like this:
It will copy and overwrite any existing configuration with the same name.
If you want to test the configuration before perform a build of the image mount it in the run time of the container.
I figured out a way to get Full Access to just any Configuration File.
I developed my solution from this tutorial about Database Container Configuration and Build
MySQL Container Build and Configuration
As well from the Official Documentation at:
Docker Volumes Configuration and Usage
This is a Multi Step Process but which only needs to be done when the Original Configuration File changed. The Concept consists of the Export and Reimport of the configured Configuration Files at Container Build Time.
(Important is the
:Z
to be able to export anything there)Dockerfile
to build a Completely Configured Web Server Container.save
ExtensionNow I can launch it and it runs smoothly:
I find that the Web Server is Up and Running:
Discussion:
Configuration Files and Package Layout are very different from Distribution to Distribution. I might not have the correct ones and so the Service might turn out to be configured not as intended.
At Build Time the Packages might get updated and some Update might change something within the Configurations as it happens often with MySQL / MariaDB. To troubleshoot any Issue I need to be able to compare with the Original Configuration Files.