Dockerfile
· 3.5 KiB · Docker
Bruto
# 強制指定使用 bookworm (Debian 12) 基礎映像檔
FROM php:8.2-apache-bookworm
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
# 1. 修正網路連線並安裝系統相依套件 (使用台灣 NCHC 鏡像站)
RUN rm -f /etc/apt/sources.list.d/debian.sources /etc/apt/sources.list && \
printf "deb https://free.nchc.org.tw/debian bookworm main contrib non-free non-free-firmware\n\
deb https://free.nchc.org.tw/debian bookworm-updates main contrib non-free non-free-firmware\n\
deb https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware\n" > /etc/apt/sources.list && \
apt-get -o Acquire::https::Verify-Peer=false update && \
apt-get install -y --no-install-recommends -o Acquire::https::Verify-Peer=false \
ca-certificates \
curl \
gnupg \
gnupg2 && \
apt-get update && apt-get install -y --no-install-recommends \
lsb-release \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libgmp-dev \
libxml2-dev \
libcurl4-gnutls-dev \
libmariadb-dev-compat \
libmariadb-dev \
libpq-dev \
libsqlite3-dev \
unixodbc-dev \
libmemcached-dev \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*
# 2. 安裝微軟 ODBC Driver for SQL Server
RUN curl -fsSL https://packages.microsoft.com/keys/microsoft.asc \
| gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg \
&& echo "deb [arch=amd64,arm64 signed-by=/usr/share/keyrings/microsoft-prod.gpg] https://packages.microsoft.com/debian/12/prod bookworm main" \
> /etc/apt/sources.list.d/mssql-release.list \
&& apt-get update && ACCEPT_EULA=Y apt-get install -y --no-install-recommends \
msodbcsql18 \
mssql-tools18 \
&& rm -rf /var/lib/apt/lists/*
ENV PATH="$PATH:/opt/mssql-tools18/bin"
# 3. 安裝 PHP 內建擴充
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-configure gmp \
&& docker-php-ext-install -j"$(nproc)" \
gd exif gmp mysqli pdo_mysql pdo_pgsql pgsql pdo_sqlite opcache
# 4. 安裝 PECL 擴充 (xmlrpc, sqlsrv, pdo_sqlsrv, memcached)
RUN pecl install channel://pecl.php.net/xmlrpc-1.0.0RC3 \
&& pecl install sqlsrv pdo_sqlsrv \
&& pecl install memcached \
&& docker-php-ext-enable xmlrpc sqlsrv pdo_sqlsrv memcached
# 5. SQL Server TLS workaround (修正舊版 SQL Server 連線問題)
RUN echo 'openssl_conf = default_conf' > /etc/ssl/openssl_custom.cnf \
&& echo '[default_conf]' >> /etc/ssl/openssl_custom.cnf \
&& echo 'ssl_conf = ssl_sect' >> /etc/ssl/openssl_custom.cnf \
&& echo '[ssl_sect]' >> /etc/ssl/openssl_custom.cnf \
&& echo 'system_default = system_default_sect' >> /etc/ssl/openssl_custom.cnf \
&& echo '[system_default_sect]' >> /etc/ssl/openssl_custom.cnf \
&& echo 'CipherString = DEFAULT@SECLEVEL=0' >> /etc/ssl/openssl_custom.cnf \
&& echo 'Options = UnsafeLegacyRenegotiation' >> /etc/ssl/openssl_custom.cnf
ENV OPENSSL_CONF=/etc/ssl/openssl_custom.cnf
# 6. 設定 Apache Log 獨立目錄 (不在 /var/www/html 內)
RUN mkdir -p /var/log/apache2/custom && chown -R www-data:www-data /var/log/apache2/custom
# 修改 Apache 預設站台設定,指向自定義 Log 路徑
RUN sed -i 's|${APACHE_LOG_DIR}/access.log|/var/log/apache2/custom/access.log|g' /etc/apache2/sites-available/000-default.conf && \
sed -i 's|${APACHE_LOG_DIR}/error.log|/var/log/apache2/custom/error.log|g' /etc/apache2/sites-available/000-default.conf
WORKDIR /var/www/html
# 啟用 Apache Rewrite 模組
RUN a2enmod rewrite
| 1 | # 強制指定使用 bookworm (Debian 12) 基礎映像檔 |
| 2 | FROM php:8.2-apache-bookworm |
| 3 | |
| 4 | SHELL ["/bin/bash", "-o", "pipefail", "-c"] |
| 5 | |
| 6 | # 1. 修正網路連線並安裝系統相依套件 (使用台灣 NCHC 鏡像站) |
| 7 | RUN rm -f /etc/apt/sources.list.d/debian.sources /etc/apt/sources.list && \ |
| 8 | printf "deb https://free.nchc.org.tw/debian bookworm main contrib non-free non-free-firmware\n\ |
| 9 | deb https://free.nchc.org.tw/debian bookworm-updates main contrib non-free non-free-firmware\n\ |
| 10 | deb https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware\n" > /etc/apt/sources.list && \ |
| 11 | apt-get -o Acquire::https::Verify-Peer=false update && \ |
| 12 | apt-get install -y --no-install-recommends -o Acquire::https::Verify-Peer=false \ |
| 13 | ca-certificates \ |
| 14 | curl \ |
| 15 | gnupg \ |
| 16 | gnupg2 && \ |
| 17 | apt-get update && apt-get install -y --no-install-recommends \ |
| 18 | lsb-release \ |
| 19 | libfreetype6-dev \ |
| 20 | libjpeg62-turbo-dev \ |
| 21 | libpng-dev \ |
| 22 | libgmp-dev \ |
| 23 | libxml2-dev \ |
| 24 | libcurl4-gnutls-dev \ |
| 25 | libmariadb-dev-compat \ |
| 26 | libmariadb-dev \ |
| 27 | libpq-dev \ |
| 28 | libsqlite3-dev \ |
| 29 | unixodbc-dev \ |
| 30 | libmemcached-dev \ |
| 31 | zlib1g-dev \ |
| 32 | && rm -rf /var/lib/apt/lists/* |
| 33 | |
| 34 | # 2. 安裝微軟 ODBC Driver for SQL Server |
| 35 | RUN curl -fsSL https://packages.microsoft.com/keys/microsoft.asc \ |
| 36 | | gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg \ |
| 37 | && echo "deb [arch=amd64,arm64 signed-by=/usr/share/keyrings/microsoft-prod.gpg] https://packages.microsoft.com/debian/12/prod bookworm main" \ |
| 38 | > /etc/apt/sources.list.d/mssql-release.list \ |
| 39 | && apt-get update && ACCEPT_EULA=Y apt-get install -y --no-install-recommends \ |
| 40 | msodbcsql18 \ |
| 41 | mssql-tools18 \ |
| 42 | && rm -rf /var/lib/apt/lists/* |
| 43 | |
| 44 | ENV PATH="$PATH:/opt/mssql-tools18/bin" |
| 45 | |
| 46 | # 3. 安裝 PHP 內建擴充 |
| 47 | RUN docker-php-ext-configure gd --with-freetype --with-jpeg \ |
| 48 | && docker-php-ext-configure gmp \ |
| 49 | && docker-php-ext-install -j"$(nproc)" \ |
| 50 | gd exif gmp mysqli pdo_mysql pdo_pgsql pgsql pdo_sqlite opcache |
| 51 | |
| 52 | # 4. 安裝 PECL 擴充 (xmlrpc, sqlsrv, pdo_sqlsrv, memcached) |
| 53 | RUN pecl install channel://pecl.php.net/xmlrpc-1.0.0RC3 \ |
| 54 | && pecl install sqlsrv pdo_sqlsrv \ |
| 55 | && pecl install memcached \ |
| 56 | && docker-php-ext-enable xmlrpc sqlsrv pdo_sqlsrv memcached |
| 57 | |
| 58 | # 5. SQL Server TLS workaround (修正舊版 SQL Server 連線問題) |
| 59 | RUN echo 'openssl_conf = default_conf' > /etc/ssl/openssl_custom.cnf \ |
| 60 | && echo '[default_conf]' >> /etc/ssl/openssl_custom.cnf \ |
| 61 | && echo 'ssl_conf = ssl_sect' >> /etc/ssl/openssl_custom.cnf \ |
| 62 | && echo '[ssl_sect]' >> /etc/ssl/openssl_custom.cnf \ |
| 63 | && echo 'system_default = system_default_sect' >> /etc/ssl/openssl_custom.cnf \ |
| 64 | && echo '[system_default_sect]' >> /etc/ssl/openssl_custom.cnf \ |
| 65 | && echo 'CipherString = DEFAULT@SECLEVEL=0' >> /etc/ssl/openssl_custom.cnf \ |
| 66 | && echo 'Options = UnsafeLegacyRenegotiation' >> /etc/ssl/openssl_custom.cnf |
| 67 | |
| 68 | ENV OPENSSL_CONF=/etc/ssl/openssl_custom.cnf |
| 69 | |
| 70 | # 6. 設定 Apache Log 獨立目錄 (不在 /var/www/html 內) |
| 71 | RUN mkdir -p /var/log/apache2/custom && chown -R www-data:www-data /var/log/apache2/custom |
| 72 | |
| 73 | # 修改 Apache 預設站台設定,指向自定義 Log 路徑 |
| 74 | RUN sed -i 's|${APACHE_LOG_DIR}/access.log|/var/log/apache2/custom/access.log|g' /etc/apache2/sites-available/000-default.conf && \ |
| 75 | sed -i 's|${APACHE_LOG_DIR}/error.log|/var/log/apache2/custom/error.log|g' /etc/apache2/sites-available/000-default.conf |
| 76 | |
| 77 | WORKDIR /var/www/html |
| 78 | |
| 79 | # 啟用 Apache Rewrite 模組 |
| 80 | RUN a2enmod rewrite |
docker-compose.yml
· 1.3 KiB · YAML
Bruto
services:
# Nginx Proxy Manager (站在最前面的門神)
app:
image: 'jc21/nginx-proxy-manager:latest'
container_name: nginxproxymanager
restart: unless-stopped
ports:
- '80:80'
- '443:443'
- '81:81'
environment:
TZ: 'Asia/Taipei'
DISABLE_IPV6: 'true'
volumes:
- ./data:/data
- ./letsencrypt:/etc/letsencrypt
- /etc/localtime:/etc/localtime:ro
dns:
- 8.8.8.8
- 1.1.1.1
# PHP Apache 服務
php:
image: timmy/php_base:v1.0
container_name: php
restart: always
tty: true
stdin_open: true
ports:
- "8001:80"
volumes:
- "./html:/var/www/html"
- "./logs:/var/log/apache2/custom" # 映射到自定義 Log 目錄
- /etc/localtime:/etc/localtime:ro
environment:
TZ: 'Asia/Taipei'
MEMCACHED_HOST: memcached
MEMCACHED_PORT: 11211
depends_on:
- memcached
# 資料庫管理工具
adminer:
image: adminer
container_name: adminer
restart: always
ports:
- "8080:8080"
environment:
TZ: 'Asia/Taipei'
volumes:
- /etc/localtime:/etc/localtime:ro
# 快取服務
memcached:
image: memcached:1.6
command: ["-m", "64", "-p", "11211", "-vv"]
environment:
TZ: 'Asia/Taipei'
volumes:
- /etc/localtime:/etc/localtime:ro
| 1 | services: |
| 2 | # Nginx Proxy Manager (站在最前面的門神) |
| 3 | app: |
| 4 | image: 'jc21/nginx-proxy-manager:latest' |
| 5 | container_name: nginxproxymanager |
| 6 | restart: unless-stopped |
| 7 | ports: |
| 8 | - '80:80' |
| 9 | - '443:443' |
| 10 | - '81:81' |
| 11 | environment: |
| 12 | TZ: 'Asia/Taipei' |
| 13 | DISABLE_IPV6: 'true' |
| 14 | volumes: |
| 15 | - ./data:/data |
| 16 | - ./letsencrypt:/etc/letsencrypt |
| 17 | - /etc/localtime:/etc/localtime:ro |
| 18 | dns: |
| 19 | - 8.8.8.8 |
| 20 | - 1.1.1.1 |
| 21 | |
| 22 | # PHP Apache 服務 |
| 23 | php: |
| 24 | image: timmy/php_base:v1.0 |
| 25 | container_name: php |
| 26 | restart: always |
| 27 | tty: true |
| 28 | stdin_open: true |
| 29 | ports: |
| 30 | - "8001:80" |
| 31 | volumes: |
| 32 | - "./html:/var/www/html" |
| 33 | - "./logs:/var/log/apache2/custom" # 映射到自定義 Log 目錄 |
| 34 | - /etc/localtime:/etc/localtime:ro |
| 35 | environment: |
| 36 | TZ: 'Asia/Taipei' |
| 37 | MEMCACHED_HOST: memcached |
| 38 | MEMCACHED_PORT: 11211 |
| 39 | depends_on: |
| 40 | - memcached |
| 41 | |
| 42 | # 資料庫管理工具 |
| 43 | adminer: |
| 44 | image: adminer |
| 45 | container_name: adminer |
| 46 | restart: always |
| 47 | ports: |
| 48 | - "8080:8080" |
| 49 | environment: |
| 50 | TZ: 'Asia/Taipei' |
| 51 | volumes: |
| 52 | - /etc/localtime:/etc/localtime:ro |
| 53 | |
| 54 | # 快取服務 |
| 55 | memcached: |
| 56 | image: memcached:1.6 |
| 57 | command: ["-m", "64", "-p", "11211", "-vv"] |
| 58 | environment: |
| 59 | TZ: 'Asia/Taipei' |
| 60 | volumes: |
| 61 | - /etc/localtime:/etc/localtime:ro |