I am trying to serve a hello_world.php file with apache and php in a docker container on Windows 10 with Docker Desktop.
Here’s the Dockerfile:
FROM php:7.3-apache
# install git and zip, both needed for composer
RUN apt-get update &&
apt-get upgrade -y &&
apt-get install -y git &&
apt-get install zip unzip
# install composer
RUN curl -sS https://getcomposer.org/installer | php --
--install-dir=/usr/bin --filename=composer && chmod +x /usr/bin/composer
RUN a2enmod headers
RUN echo 'ServerName localhost' >> /etc/apache2/apache2.conf
COPY . /var/www/html
WORKDIR /var/www/html
#RUN composer install
EXPOSE 80
As you can see, some of the additional code for setting up composer etc. (so I can dockerize an existing PHP application) is even commented out but it does not work with even a basic hello world php file and no other files (no .htaccess for example).
Firstly, I build the image with docker build .
. When I then execute docker run -it -p 8000:80 d7cd1255a20f
, I get the console output
[Tue Jun 02 16:01:29.592455 2020] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.3.18 configured -- resuming normal operations
[Tue Jun 02 16:01:29.592531 2020] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
Looks fine to me.
I open http://localhost:8000
in my browser and get “Can’t establish a secure connection. ERR_SSL_PROTOCOL_ERROR”. The server log shows (two lines each time I load the page in my browser):
172.17.0.1 - - [02/Jun/2020:16:02:55 +0000] "x16x03x01x02" 400 0 "-" "-"
172.17.0.1 - - [02/Jun/2020:16:02:55 +0000] "x16x03x01x02" 400 0 "-" "-"
I have already researched this and it looks like it’s the beginning of a TLS handshake.
How can I get this to work?
2
Answers
Do you have any .htaccess file inside /var/www/html? It looks like Apache is performing an automated redirect to HTTPS. Building the image with an empty directory as /var/www/html and running
docker run -it -p 8000:80 d7cd1255a20f
correctly runs over HTTP.okay Try this
Follow the folder structure
After this run following command
When the build is completed.
Please make sure port 80 is not in use, or what you can do change the port number
PS: directory structure is not mandatory. I added just to structure the example 😉