Hoping someone can advise… I have been trying to create a simple apache container that configures a virtual host in apache then displays its custom index.html. Outside of docker, this works fine, but when I attempt to replicate such config in a Dockerfile, it either fails with ‘can’t locate apache2’ error if I try a ubuntu base image or it just displays the default ‘It works!’ index.html if I try the httpd 2.4 base image. My latest attempt at Dockerfile is as follows:
could you please provide the content of tutorialDocker.conf and the way you’ve started the container?
As apache is not part of the default-ubuntu-image the mentioned error-message is normal - you have to install it using apt-get update && apt-get install apache2 or use an image which is specialized for providing the apache-service (as you did using the httpd-image).
I would prefer the way using the httpd-image as it should be smaller and provide less additional and not needed software (which is good for security-reason).
TLDR; config-file was placed at wrong location, was not loaded and configuration for document-root was missing
Hello,
I’m sorry for the bad experience you received from the tutorial (which tutorial?) - but with the unmodified Dockerfile and .conf-file it would not work.
I did some tests and modified the Dockerfile to
FROM httpd:2.4
LABEL maintainer="someemail@gmail.com"
RUN mkdir -p /var/www/html/tutorial_docker/ && sed -i -E 's:^#(Include conf/extra/httpd-default.conf):\1:' /usr/local/apache2/conf/httpd.conf
COPY ./index.html /var/www/html/tutorial_docker/
COPY ./tutorialDocker.conf /usr/local/apache2/conf/extra/httpd-default.conf
EXPOSE 80
to place your tutorialDocker.conf within the image as /usr/local/apache2/conf/extra/httpd-default.conf and to load it by modifying the /usr/local/apache2/conf/httpd.conf.
to send the log-information to the place where you can get them with docker logs webserver and to specify some settings about the directory you have specified as DocumentRoot. Without the <Directory ... apache will return a 403 - Forbidden.
Hi Matthias thanks for taking such effort to elaborate on my question. It’s greatly appreciated.
I just called this my own personal docker tutorial, I’d previously followed some tutorial on how to stand up a simple website in Apache and figured this could be replicated in docker. Seems however, I was not aware of the nuances of such a task.
I tried building your script but unfortunately it failed with the following error:
I’m sorry for this error. I forgot the -E-parameter for sed. Without this parameter the regular expressions and grouping will not work. The answer above is now updated.
I’ve reviewed your fine work and believe I now understand how you scripted the Dockerfile. Basically you utilised stream editor linux command to find a string in httpd.conf so as to be able to uncomment / include httpd-default.conf in this Apache implementation. You then overwrite httpd-default.conf 's contents with tutorialDocker.conf, which you had previously defined to properly enable my virtual host as well as enable its logging for the docker logs [container name] command.
This has been a constructive exercise and I appreciate your time. Thanks heaps!