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 \ |     && docker-php-ext-install xml \ | ||||||
|     && a2enmod rewrite |     && 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 port 80 | ||||||
| EXPOSE 80 | EXPOSE 80 | ||||||
|  | @ -4,5 +4,9 @@ FROM mariadb:latest | ||||||
| # Add the install.sql file to the docker image | # Add the install.sql file to the docker image | ||||||
| ADD install/assets/install.sql /docker-entrypoint-initdb.d | 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 port 3306 | ||||||
| EXPOSE 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 { | class Migration_modify_eQSL_url extends CI_Migration { | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,5 +1,3 @@ | ||||||
| version: "3.8" |  | ||||||
| 
 |  | ||||||
| networks: | networks: | ||||||
|   mynet: |   mynet: | ||||||
| 
 | 
 | ||||||
|  | @ -12,9 +10,10 @@ services: | ||||||
|       - "80:80" |       - "80:80" | ||||||
|     volumes: |     volumes: | ||||||
|       - ./:/var/www/html:rw |       - ./:/var/www/html:rw | ||||||
|     command: ["./script.sh"] |     command: ["/usr/local/bin/startup.sh"] | ||||||
|     depends_on: |     depends_on: | ||||||
|       - db |       db: | ||||||
|  |         condition: service_healthy | ||||||
|     networks: |     networks: | ||||||
|       - mynet |       - mynet | ||||||
|     restart: on-failure |     restart: on-failure | ||||||
|  | @ -30,11 +29,11 @@ services: | ||||||
|     networks: |     networks: | ||||||
|       - mynet |       - mynet | ||||||
|     healthcheck: |     healthcheck: | ||||||
|       test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"] |       test: ["CMD", "/usr/local/bin/healthcheck.sh"] | ||||||
|       timeout: 30s |       timeout: 20s | ||||||
|       retries: 20 |       retries: 10 | ||||||
|       interval: 15s |       interval: 10s | ||||||
|       start_period: 60s |       start_period: 40s | ||||||
| 
 | 
 | ||||||
| volumes: | volumes: | ||||||
|   db_data: {} |   db_data: {} | ||||||
|  |  | ||||||
							
								
								
									
										14
									
								
								script.sh
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								script.sh
									
									
									
									
									
								
							|  | @ -81,11 +81,15 @@ echo "Replacement complete." | ||||||
| 
 | 
 | ||||||
| # Wait for database to be ready | # Wait for database to be ready | ||||||
| echo "Waiting 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 "Connecting to: Host=$MYSQL_HOST, User=$MYSQL_USER, Database=$MYSQL_DATABASE" | ||||||
|     echo "Database is not ready yet. Waiting 5 seconds..." | 
 | ||||||
|     sleep 5 | # Give the database a moment, then test connection once | ||||||
| done | sleep 2 | ||||||
| echo "Database is ready!" | 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 | # Set Permissions | ||||||
| chown -R root:www-data /var/www/html/application/config/ | chown -R root:www-data /var/www/html/application/config/ | ||||||
|  |  | ||||||
		正在加载…
	
		在新工单中引用