Update Docker setup and improve health checks
Dockerfile now copies and sets up script.sh as startup.sh. Dockerfile-db adds a custom healthcheck script using mariadb-admin. docker-compose.yml updates service commands, healthcheck configuration, and dependency conditions. script.sh improves database readiness logic. Minor fix in migration file to remove BOM character.
这个提交包含在:
父节点
7acbffd2cc
当前提交
531cb1b1e3
共有 5 个文件被更改,包括 26 次插入 和 15 次删除
|
|
@ -24,5 +24,9 @@ RUN apt-get update && apt-get install -y \
|
|||
&& docker-php-ext-install xml \
|
||||
&& a2enmod rewrite
|
||||
|
||||
# Copy script.sh and make it executable
|
||||
COPY script.sh /usr/local/bin/startup.sh
|
||||
RUN sed -i 's/\r$//' /usr/local/bin/startup.sh && chmod +x /usr/local/bin/startup.sh
|
||||
|
||||
# Expose port 80
|
||||
EXPOSE 80
|
||||
|
|
@ -4,5 +4,9 @@ FROM mariadb:latest
|
|||
# Add the install.sql file to the docker image
|
||||
ADD install/assets/install.sql /docker-entrypoint-initdb.d
|
||||
|
||||
# Create a healthcheck script that uses mariadb-admin
|
||||
RUN echo '#!/bin/bash\nmariadb-admin ping -h "localhost" --silent' > /usr/local/bin/healthcheck.sh \
|
||||
&& chmod +x /usr/local/bin/healthcheck.sh
|
||||
|
||||
# Expose port 3306
|
||||
EXPOSE 3306
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Migration_modify_eQSL_url extends CI_Migration {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
version: "3.8"
|
||||
|
||||
networks:
|
||||
mynet:
|
||||
|
||||
|
|
@ -12,9 +10,10 @@ services:
|
|||
- "80:80"
|
||||
volumes:
|
||||
- ./:/var/www/html:rw
|
||||
command: ["./script.sh"]
|
||||
command: ["/usr/local/bin/startup.sh"]
|
||||
depends_on:
|
||||
- db
|
||||
db:
|
||||
condition: service_healthy
|
||||
networks:
|
||||
- mynet
|
||||
restart: on-failure
|
||||
|
|
@ -30,11 +29,11 @@ services:
|
|||
networks:
|
||||
- mynet
|
||||
healthcheck:
|
||||
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
|
||||
timeout: 30s
|
||||
retries: 20
|
||||
interval: 15s
|
||||
start_period: 60s
|
||||
test: ["CMD", "/usr/local/bin/healthcheck.sh"]
|
||||
timeout: 20s
|
||||
retries: 10
|
||||
interval: 10s
|
||||
start_period: 40s
|
||||
|
||||
volumes:
|
||||
db_data: {}
|
||||
|
|
|
|||
12
script.sh
12
script.sh
|
|
@ -81,11 +81,15 @@ echo "Replacement complete."
|
|||
|
||||
# Wait for database to be ready
|
||||
echo "Waiting for database to be ready..."
|
||||
until mysql -h"$MYSQL_HOST" -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" -e "SELECT 1" > /dev/null 2>&1; do
|
||||
echo "Database is not ready yet. Waiting 5 seconds..."
|
||||
sleep 5
|
||||
done
|
||||
echo "Connecting to: Host=$MYSQL_HOST, User=$MYSQL_USER, Database=$MYSQL_DATABASE"
|
||||
|
||||
# Give the database a moment, then test connection once
|
||||
sleep 2
|
||||
if mariadb -h"$MYSQL_HOST" -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" -D"$MYSQL_DATABASE" -e "SELECT 1;" >/dev/null 2>&1; then
|
||||
echo "Database is ready!"
|
||||
else
|
||||
echo "Database connection failed, but continuing anyway since healthcheck passed..."
|
||||
fi
|
||||
|
||||
# Set Permissions
|
||||
chown -R root:www-data /var/www/html/application/config/
|
||||
|
|
|
|||
正在加载…
在新工单中引用