Heim  >  Fragen und Antworten  >  Hauptteil

So erstellen Sie ordnungsgemäß einen Apache2-Container in Docker

Ich habe die folgende Docker-Datei:

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

Ich führe den Container auf diesem Bild folgendermaßen aus:

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 ist:

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>

Es gibt keine Fehler bei der Bild- oder Containererstellung, aber wenn ich versuche, darauf zuzugreifen localhost:8080, lädt die Website 15 Minuten lang ohne Ergebnisse.

Was habe ich falsch gemacht? Danke

P粉428986744P粉428986744233 Tage vor382

Antworte allen(1)Ich werde antworten

  • P粉986937457

    P粉9869374572024-02-04 10:28:59

    我无法发表评论,但这里有几个调试问题:

    • 编辑 docker 文件后是否重建了镜像?
    • 当您发出请求时,网络选项卡会显示什么? (有没有重定向)
    • 您可以在不使用 htaccess 配置的情况下尝试看看这是否是问题所在吗?
    • 您的 index.php 文件在基本目录 (var/www/html) 中是什么样子?

    Antwort
    0
  • StornierenAntwort