skip to Main Content

When loading docker-compose up, wordpress loads on the url but the mysqli_connect function is undefined because of the absence of the extension.

I have tried to add the following under the fpm image

command: “docker-php-ext-install mysqli”

I have tried to add a Dockerfile into the directory of the docker-compose.yml file containing

version: "3"

services:
  #database
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: wordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    networks:
      - wpsite
  # webserver
  nginx:
    image: nginx:latest
    ports:
      - "8080:80"
    links:
      - fpm
    volumes:
      - /Users/connergesbocker/Github/cbgesbocker/dotfiles/root/etc/nginx/conf.d/village.conf:/etc/nginx/conf.d/village.conf
      - /Users/connergesbocker/WordPress:/WordPress
    networks:
      - wpsite
  # phpmyadmin
  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    restart: always
    ports:
      - "8888:8888"
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: wordpress
    networks:
      - wpsite
  fpm:
    image: php:5.6.20-fpm
    ports:
      - "90:9000"
    # command: "docker-php-ext-install mysqli"
    links:
      - db
    volumes:
      - /Users/connergesbocker/WordPress:/WordPress
    working_dir: "/"
    networks:
      - wpsite
networks:
  wpsite:
volumes:
  db_data:```

2

Answers


  1. your override will install the extension but the container will stop after installation because php-fpm will not start by overriding CMD. Replace the command with below one.

    command:
      - /bin/sh
      - -c
      - |
          docker-php-ext-install mysqli 
          echo "extension installed.....starting php-fpm........................................"
          php-fpm
    

    enter image description here

    Login or Signup to reply.
  2. You could customize your dockerfile & add install in it:

    Dockerfile:

    FROM php:5.6.20-fpm
    RUN docker-php-ext-install mysqli
    

    Part of docker-compose.yaml:

    fpm:
      build: .
      image: myphp:1
      ports:
        - "90:9000"
      # command: "docker-php-ext-install mysqli"
      links:
        - db
      volumes:
        - /Users/connergesbocker/WordPress:/WordPress
      working_dir: "/"
      networks:
        - wpsite
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search