fix(1panel): join 1panel-network and connect MySQL/Redis by container name

Per 1Panel App Store architecture, bridge apps must use Docker DNS on 1panel-network instead of host.docker.internal.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Nexus Deploy
2026-06-06 05:35:04 +08:00
parent da0424a268
commit 6951b8049f
9 changed files with 215 additions and 66 deletions
+55 -1
View File
@@ -34,6 +34,7 @@ NEXUS_PUBLISH_PORT="${NEXUS_PUBLISH_PORT:-8600}"
GIT_BRANCH="${NEXUS_GIT_BRANCH:-main}"
COMPOSE_FILE="docker/docker-compose.prod.yml"
COMPOSE_1PANEL="docker/docker-compose.1panel.yml"
ENV_PROD="docker/.env.prod"
HOST_PROFILE_FILE="docker/.host-profile"
@@ -186,6 +187,51 @@ apply_pool_to_env_prod() {
[[ -n "$overflow" ]] && sed -i "s|^NEXUS_DB_MAX_OVERFLOW=.*|NEXUS_DB_MAX_OVERFLOW=${overflow}|" "$env_file"
}
has_1panel_network() {
docker network inspect 1panel-network >/dev/null 2>&1
}
upsert_env_var() {
local file="$1" key="$2" val="$3"
if grep -qE "^${key}=" "$file" 2>/dev/null; then
sed -i "s|^${key}=.*|${key}=${val}|" "$file"
else
echo "${key}=${val}" >>"$file"
fi
}
sync_1panel_service_hosts() {
local root="$1"
local env_file="$root/$ENV_PROD"
local detect="$root/deploy/detect-1panel-services.sh"
[[ -f "$env_file" ]] || return 0
if ! has_1panel_network; then
return 0
fi
if [[ ! -x "$detect" ]]; then
chmod +x "$detect" 2>/dev/null || true
fi
if [[ ! -x "$detect" ]]; then
warn "未找到 detect-1panel-services.sh,跳过 1Panel 容器名探测"
return 0
fi
local line mysql_host redis_host
while IFS= read -r line; do
case "$line" in
NEXUS_1PANEL_DB_HOST=*)
mysql_host="${line#NEXUS_1PANEL_DB_HOST=}"
upsert_env_var "$env_file" NEXUS_1PANEL_DB_HOST "$mysql_host"
info "1Panel MySQL 容器: $mysql_host(安装向导将预填为数据库主机)"
;;
NEXUS_1PANEL_REDIS_HOST=*)
redis_host="${line#NEXUS_1PANEL_REDIS_HOST=}"
upsert_env_var "$env_file" NEXUS_1PANEL_REDIS_HOST "$redis_host"
info "1Panel Redis 容器: $redis_host"
;;
esac
done < <("$detect" 2>/dev/null || true)
}
compose_cmd() {
local root="$1"
shift
@@ -196,7 +242,11 @@ compose_cmd() {
exit 1
fi
cd "$root"
docker compose -f "$COMPOSE_FILE" --env-file "$ENV_PROD" --env-file "$prof" "$@"
local -a compose_args=(-f "$COMPOSE_FILE")
if has_1panel_network && [[ -f "$COMPOSE_1PANEL" ]]; then
compose_args+=(-f "$COMPOSE_1PANEL")
fi
docker compose "${compose_args[@]}" --env-file "$ENV_PROD" --env-file "$prof" "$@"
}
rand_secret() {
@@ -555,6 +605,10 @@ compose_up() {
local root="$1"
save_host_profile "$root"
purge_legacy_bundled_services "$root"
sync_1panel_service_hosts "$root"
if has_1panel_network; then
info "已接入 1panel-networkMySQL/Redis 使用 1Panel 容器名互联)"
fi
info "档位: ${NEXUS_PROFILE}(仅 Nexus 容器;MySQL/Redis 请自行安装)"
info "构建并启动(首次约 1020 分钟)..."
compose_cmd "$root" up -d --build --remove-orphans