使用 wordpress docker 鏡像遇到 max file upload 的限制

最近在幫公司的部門搞個 blog, 由於部署及維護上希望減少管理上的工作,所以就使用 docker compose 來設置,架設上沒有什麼問題,但在上傳自訂的外掛及佈景時發現預設的官方鏡像設定是有限制 2MB 的上傳大小,這也是 PHP的預設設定,若是不用 docker 鏡像就是找出 php.ini 去修改下面這二個參數

; Maximum allowed size for uploaded files.
upload_max_filesize = 2M

; Must be greater than or equal to upload_max_filesize
post_max_size = 10M

但在 docker 鏡像中要嘛就是在建立鏡像時(build)修改,不然就是在啟動時做點手腳去變更相關參數,或啟動後去修改,自己比較喜歡用後者方式,加個設定檔後再覆寫掉鏡像的設置去變更掉相關的環境限制,所以這邊做個記錄一下

建立 uploads.ini

file_uploads = On
memory_limit = 64M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 600

修改 docker-compose.yml 然後將 uploads.ini 掛載至對應的路徑下後重啟 container即可

version: '3.3'

services:
   db:
     image: mariadb
     volumes:
       - /opt/mariadb:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: [db_root_password]
       MYSQL_DATABASE: [database_name]
       MYSQL_USER: [db_user_name]
       MYSQL_PASSWORD: [db_user_password]

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "80:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: [db_user_name]
       WORDPRESS_DB_PASSWORD: [db_user_password]
       WORDPRESS_DB_NAME: [database_name]
     volumes:
       - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
volumes:
    db_data: {}

Author: jerryw1974

learning and focus on computer science, cloud infrastructure, virtualization and information security, technical, networking,platform system and cyber-security related topic.