简体   繁体   English

如何在 Docker 中正确创建 Apache2 容器

[英]How to proper create Apache2 container in Docker

I have following Dockerfile:我有以下 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

And I am running container on that images in 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: /home/xxx/apache2.conf是:

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 aren't any errors during creating image or creating container, but when I try to visit localhost:8080 , site is loading for 15 minutes without any result.在创建镜像或创建容器的过程中没有任何错误,但是当我尝试访问localhost:8080时,站点正在加载 15 分钟而没有任何结果。

What am I doing wrong?我究竟做错了什么? Thanks谢谢

I cannot comment, but here is a couple of debugging questions:我无法发表评论,但这里有几个调试问题:

  • did you rebuild the image after editing your docker file?您在编辑 docker 文件后重建图像了吗?
  • what the network tabs says when you do a request?当您发出请求时,网络选项卡会显示什么? (Is there any redirections) (是否有任何重定向)
  • can you try without you htaccess config to see if this is the problem?你可以在没有你的 htaccess 配置的情况下尝试看看这是否是问题所在?
  • what is your index.php file looks like in the base directory (var/www/html)?你的 index.php 文件在基本目录 (var/www/html) 中是什么样的?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM