vi dockerfile_web_wp8225
FROM php:8.2.25-apache
RUN rm -rf /etc/localtime && ln -s /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime
RUN apt-get update && apt-get install libzip-dev libpng-dev libicu-dev -y && apt-get clean -y && rm -r /var/lib/apt/lists/*
RUN docker-php-ext-install mysqli gd exif zip intl && a2enmod ssl && a2ensite default-ssl
docker build -f dockerfile_web_wp8225 -t web_wp:8225 --no-cache=true .
docker tag web_wp:8225 web_wp:latest
vi dockercompose_web.yml
services:
web:
image: web_wp
volumes:
- html:/var/www/html
- apache2:/etc/apache2
- php:/usr/local/etc/php/
restart: unless-stopped
ports:
- xxx.xxx.xxx.xxx:80:80
- xxx.xxx.xxx.xxx:443:443
container_name: my_web
network_mode: bridge
database:
image: mysql:8.4.2
volumes:
- mysql:/var/lib/mysql
restart: unless-stopped
ports:
- xxx.xxx.xxx.xxx:3306:3306
container_name: my_mysql
network_mode: bridge
environment:
MYSQL_ROOT_PASSWORD: RootPassword
MYSQL_DATABASE: my_web_db
MYSQL_USER: myname
MYSQL_PASSWORD: db_password
volumes:
html:
driver: local
apache2:
driver: local
php:
driver: local
mysql:
driver: local
docker compose -p my_web -f dockercompose_web.yml up -d
這個時候Container應該可以正常服務的, 但是沒有
docker logs my_web
SSLCertificateFile: file '/etc/ssl/certs/ssl-cert-snakeoil.pem' does not exist or is empty
AH00526: Syntax error on line 31 of /etc/apache2/sites-enabled/default-ssl.conf:
因為我在上面啟用了SSL a2enmod ssl && a2ensite, 但是預設証書路徑不正確
mkdir /var/lib/docker/volumes/my_web_apache2/_data/certs
vi /var/lib/docker/volumes/my_web_apache2/_data/sites-enabled/default-ssl.conf
SSLCertificateFile /etc/apache2/certs/xxx.cer
SSLCertificateKeyFile /etc/apache2/certs/xxx.key
SSLCACertificateFile /etc/apache2/certs/rootCA.cer
docker restart my_web
上面已經可以正常看到web服務的反應
下面測試一下Docker更新php新版本
vi dockerfile_web_wp8312
FROM php:8.3.12-apache
RUN rm -rf /etc/localtime && ln -s /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime
RUN apt-get update && apt-get install libzip-dev libpng-dev -y && apt-get clean -y && rm -r /var/lib/apt/lists/*
RUN docker-php-ext-install mysqli gd && a2enmod ssl && a2ensite default-ssl
docker build -f dockerfile_web_wp8312 -t web_wp:8312 --no-cache=true .
docker tag web_wp:8312 web_wp:latest
docker compose -p my_web -f dockercompose_web.yml up -d
Remark
經phpinfo驗查後, 好像還是需要在container install mysqli gd exif zip intl, 還未能搞清楚能在否image pre-install
docker exec -it my_web bash
docker-php-ext-install mysqli gd exif zip intl