Docker Image: Integration of PHP 8.0, Apache and phpMyAdmin
P粉186017651
P粉186017651 2024-03-31 18:19:17
0
1
440

I'm creating an image for a php8 project running on apache and using phpMyAdmin, my Dockerfile is as follows:

FROM php:8.0-apache
RUN apt-get update -y && apt-get install -y libmariadb-dev && docker-php-ext-install mysqli && docker-php-ext-install pdo_mysql
WORKDIR /var/www/html

My docker-compose.yml is as follows:

services:
  php-apache-environment:
    container_name: php-apache
    image: php:8.0-apache
    volumes:
      - ./php/src:/var/www/html/
    ports:
      - 8000:80

  db:
    container_name: db
    image: mysql:latest
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: MYSQL_ROOT_PASSWORD
      MYSQL_DATABASE: MY_DATABASE
      MYSQL_USER: MYSQL_USER
      MYSQL_PASSWORD: MYSQL_PASSWORD
    ports:
      - "9906:3306"
  phpmyadmin:
    image: phpmyadmin:latest
    ports:
      - '8080:80'
    restart: always
    environment:
      PMA_HOST: db
    depends_on:
      - db

For me, everything is fine, but when I run "docker compose up --build", the container starts, but he does not install "mysqli" and "pdo_mysql" as I requested in the Dockerfile .

However, if I log into the PHP container via CLI and run docker-php-ext-install mysqli and docker-php-ext-install pdo_mysql, it works , I just need to restart the PHP container.

But, I don't know why, I can't install it from the beginning?

thanks for your help.

P粉186017651
P粉186017651

reply all(1)
P粉541551230

Thanks to Lety's comment, we only need to change line 4 of docker-compose.yml author:

build: ./php

(indicates the directory where the Dockerfile is located) and it works.

CV: Do not change Dockerfile . Change the docker-compose.yml Author:

version: '3.8'
services:
  php-apache-environment:
    container_name: php-apache
    build: ./php
    volumes:
      - ./php/src:/var/www/html/
    ports:
      - 8000:80

  db:
    container_name: db
    image: mysql:latest
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: MYSQL_ROOT_PASSWORD
      MYSQL_DATABASE: MY_DATABASE
      MYSQL_USER: MYSQL_USER
      MYSQL_PASSWORD: MYSQL_PASSWORD
    ports:
      - "9906:3306"
  phpmyadmin:
    image: phpmyadmin:latest
    ports:
      - '8080:80'
    restart: always
    environment:
      PMA_HOST: db
    depends_on:
      - db
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template