简体   繁体   中英

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.

Docker-Compose:

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. 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. I then restart apache with kill -HUP 1 and the Website works as intended. Does anyone know what the problem is here?

Have you tried doing the install and apache restart inside a Dockerfile instead?

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:

[...]

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

[...]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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