How to properly create an Apache2 container in Docker
P粉428986744
P粉428986744 2024-02-03 20:28:19
0
1
407

I have the following Dockerfile:

FROM php:8.0-apache
WORKDIR /var/www/html

EXPOSE 80

RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf && \
    rm -rf /etc/apache2/sites-enabled/000-default.conf && \
    service apache2 restart

I run the container on this image this way:

sudo docker run -d --name apache2-container -e TZ=UTC -p 8080:80 -v /home/xxx/www:/var/www/html -v /home/xxx/apache2.conf:/etc/apache2/apache2.conf my_image

/home/xxx/apache2.conf is:

User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
ErrorLog ${APACHE_LOG_DIR}/error.log

HostnameLookups Off

# Include module configuration:
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

# Include list of ports to listen on
Include ports.conf

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

<Directory /srv/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

ServerName localhost

<VirtualHost *:80>
    DocumentRoot /var/www/html
</VirtualHost>

There are no errors during image creation or container creation, but when I try to access localhost:8080, the website loads for 15 minutes with no results.

What did i do wrong? Thanks

P粉428986744
P粉428986744

reply all(1)
P粉986937457

I can't comment, but here are a couple of debugging questions:

  • Have you rebuilt the image after editing the docker file?
  • What does the Network tab show when you make a request? (With or without redirection)
  • Can you try it without htaccess configuration to see if this is the problem?
  • What does your index.php file look like in the base directory (var/www/html)?
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!