简体   繁体   English

安装 mysqli 扩展后的 Docker php:php7.4-apache boot-loop

[英]Docker php:php7.4-apache boot-loop after installing mysqli extension

i am currently trying to run my Website in a Docker container using mysql and php with apache.我目前正在尝试使用 mysql 和 php 和 apache 在 Docker 容器中运行我的网站。

Docker-Compose: Docker-撰写:

version: '3.7'
services:
  mysql:
    image: mysql:latest
    container_name: mysql
    restart: always
    environment:
      //Database configuration variables

    volumes:
      - ./data/mysql/database:/var/lib/mysql

  webserver:
    image: php:7.4.12-apache
    depends_on:
      - mysql
    restart: always
    volumes:
      - ./data/webserver:/var/www/html/
    ports:
      - 8888:80
    command: bash -c "docker-php-ext-install mysqli && kill -HUP 1"

  phpmyadmin:
    depends_on:
      - mysql
    image: phpmyadmin:latest
    container_name: phpmyadmin
    links:
      - mysql:db
    restart: always
    ports:
     - 8889:80
    volumes:
     - /sessions

The problem began after i added the command-block to the webserver-container.在我将命令块添加到 webserver-container 后,问题就开始了。 Without it, the container runs perfectly and i can access the website.没有它,容器运行完美,我可以访问网站。 But with the command, the container gets stuck in a boot-loop and it seems that it tries to run the command over and over.但是使用该命令,容器会卡在引导循环中,并且它似乎试图一遍又一遍地运行该命令。 At least thats what i guess after looking at the log of the webserver container.至少这是我在查看网络服务器容器的日志后的猜测。 However when i use docker exec -it *webserver* bash and run the installation command directly in the container, it works perfectly.但是,当我使用docker exec -it *webserver* bash并直接在容器中运行安装命令时,它运行良好。 I then restart apache with kill -HUP 1 and the Website works as intended.然后我用kill -HUP 1重新启动 apache,网站按预期工作。 Does anyone know what the problem is here?有谁知道这里的问题是什么?

Have you tried doing the install and apache restart inside a Dockerfile instead?您是否尝试过在 Dockerfile 中进行安装和 apache 重新启动?

Something like:就像是:

FROM php:7.4.12-apache

RUN apt-get clean && apt-get update && apt-get install -y php7.4-mysqli; 

RUN service apache2 restart;

Then your docker-compose could be:那么你的 docker-compose 可能是:

[...]

webserver:
    build:
      context: .
      dockerfile: docker/webserver/Dockerfile
    depends_on:
      - mysql
    restart: always
    volumes:
      - ./data/webserver:/var/www/html/
    ports:
      - 8888:80

[...]

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

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