如何使用NGINX,PHP-FPM在docker-compose.yml文件中加载mysqli扩展

时间:2019-07-18 21:17:23

标签: php mysql wordpress docker docker-compose

在加载docker-compose时,wordpress会在URL上加载,但由于缺少扩展名,mysqli_connect函数未定义。

我试图在fpm图片下添加以下内容

命令:“ docker-php-ext-install mysqli”

我尝试将Dockerfile添加到包含

的docker-compose.yml文件的目录中
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 个答案:

答案 0 :(得分:0)

您的替代将安装扩展,但是容器将在安装后停止,因为php-fpm不会以覆盖CMD开头。用下面的命令替换该命令。

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

enter image description here

答案 1 :(得分:0)

您可以自定义dockerfile并在其中添加安装:

Dockerfile:

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

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