Closed yincangshiwei closed 1 month ago
👀 @yincangshiwei
Thank you for raising an issue. We will investigate into the matter and get back to you as soon as possible. Please make sure you have given us as much context as possible.\ 非常感谢您提交 issue。我们会尽快调查此事,并尽快回复您。 请确保您已经提供了尽可能多的背景信息。
构建时引入 --build-arg USE_CN_MIRROR=true
参数试试,多半网络问题
docker build -t lobe-chat:local --build-arg USE_CN_MIRROR=true --no-cache .
@yincangshiwei 你好!我是Dosu,一个可以帮助你解决bug、回答问题并成为贡献者的机器人。我在这里帮助你,等待人类维护者的到来。
I found a similar closed issue, [Bug] Docker build 构建失败, which was resolved by a pull request that fixed OAuth errors on Docker deployment [1].
To fix the Dockerfile error related to setting up the npm registry and installing dependencies using corepack and pnpm, ensure that the environment variable COREPACK_NPM_REGISTRY
is correctly set and used. Here is the relevant part of the Dockerfile with the necessary steps:
## Base image for all the stages
FROM node:20-alpine AS base
ARG USE_CN_MIRROR
RUN \
# If you want to build docker in China, build with --build-arg USE_CN_MIRROR=true
if [ "${USE_CN_MIRROR:-false}" = "true" ]; then \
sed -i "s/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g" "/etc/apk/repositories"; \
fi \
# Add required package & update base package
&& apk update \
&& apk add --no-cache bind-tools proxychains-ng sudo \
&& apk upgrade --no-cache \
# Add user nextjs to run the app
&& addgroup --system --gid 1001 nodejs \
&& adduser --system --uid 1001 nextjs \
&& chown -R nextjs:nodejs "/etc/proxychains" \
&& echo "nextjs ALL=(ALL) NOPASSWD: /bin/chmod * /etc/resolv.conf" >> /etc/sudoers \
&& rm -rf /tmp/* /var/cache/apk/*
## Builder image, install all the dependencies and build the app
FROM base AS builder
ARG USE_CN_MIRROR
ENV NEXT_PUBLIC_SERVICE_MODE="server" \
APP_URL="http://app.com" \
DATABASE_DRIVER="node" \
DATABASE_URL="postgres://postgres:password@localhost:5432/postgres" \
KEY_VAULTS_SECRET="use-for-build"
# Sentry
ENV NEXT_PUBLIC_SENTRY_DSN="" \
SENTRY_ORG="" \
SENTRY_PROJECT=""
# Posthog
ENV NEXT_PUBLIC_ANALYTICS_POSTHOG="" \
NEXT_PUBLIC_POSTHOG_HOST="" \
NEXT_PUBLIC_POSTHOG_KEY=""
# Umami
ENV NEXT_PUBLIC_ANALYTICS_UMAMI="" \
NEXT_PUBLIC_UMAMI_SCRIPT_URL="" \
NEXT_PUBLIC_UMAMI_WEBSITE_ID=""
# Node
ENV NODE_OPTIONS="--max-old-space-size=8192"
WORKDIR /app
COPY package.json ./
COPY .npmrc ./
RUN \
# If you want to build docker in China, build with --build-arg USE_CN_MIRROR=true
if [ "${USE_CN_MIRROR:-false}" = "true" ]; then \
export SENTRYCLI_CDNURL="https://npmmirror.com/mirrors/sentry-cli"; \
npm config set registry "https://registry.npmmirror.com/"; \
fi \
# Set the registry for corepack
&& export COREPACK_NPM_REGISTRY=$(npm config get registry | sed 's/\/$//') \
# Enable corepack
&& corepack enable \
# Use pnpm for corepack
&& corepack use pnpm \
# Install the dependencies
&& pnpm i \
# Add sharp and db migration dependencies
&& mkdir -p /deps \
&& pnpm add sharp pg drizzle-orm --prefix /deps
COPY . .
# run build standalone for docker version
RUN npm run build:docker
## Application image, copy all the files for production
FROM scratch AS app
COPY --from=builder /app/public /app/public
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder /app/.next/standalone /app/
COPY --from=builder /app/.next/static /app/.next/static
# copy dependencies
COPY --from=builder /deps/node_modules/.pnpm /app/node_modules/.pnpm
COPY --from=builder /deps/node_modules/pg /app/node_modules/pg
COPY --from=builder /deps/node_modules/drizzle-orm /app/node_modules/drizzle-orm
# Copy database migrations
COPY --from=builder /app/src/database/server/migrations /app/migrations
COPY --from=builder /app/scripts/migrateServerDB/docker.cjs /app/docker.cjs
COPY --from=builder /app/scripts/migrateServerDB/errorHint.js /app/errorHint.js
## Production image, copy all the files and run next
FROM base
# Copy all the files from app, set the correct permission for prerender cache
COPY --from=app --chown=nextjs:nodejs /app /app
ENV NODE_ENV="production"
# set hostname to localhost
ENV HOSTNAME="0.0.0.0" \
PORT="3210"
# General Variables
ENV ACCESS_CODE="" \
APP_URL="" \
API_KEY_SELECT_MODE="" \
DEFAULT_AGENT_CONFIG="" \
SYSTEM_AGENT="" \
FEATURE_FLAGS="" \
PROXY_URL=""
# Database
ENV KEY_VAULTS_SECRET="" \
DATABASE_DRIVER="node" \
DATABASE_URL=""
# Next Auth
ENV NEXT_AUTH_SECRET="" \
NEXT_AUTH_SSO_PROVIDERS="" \
NEXTAUTH_URL=""
# S3
ENV NEXT_PUBLIC_S3_DOMAIN="" \
S3_PUBLIC_DOMAIN="" \
S3_ACCESS_KEY_ID="" \
S3_BUCKET="" \
S3_ENDPOINT="" \
S3_SECRET_ACCESS_KEY=""
# Model Variables
ENV \
# Ai360
AI360_API_KEY="" \
# Anthropic
ANTHROPIC_API_KEY="" ANTHROPIC_PROXY_URL="" \
# Amazon Bedrock
AWS_ACCESS_KEY_ID="" AWS_SECRET_ACCESS_KEY="" AWS_REGION="" AWS_BEDROCK_MODEL_LIST="" \
# Azure OpenAI
AZURE_API_KEY="" AZURE_API_VERSION="" AZURE_ENDPOINT="" AZURE_MODEL_LIST="" \
# Baichuan
BAICHUAN_API_KEY="" \
# DeepSeek
DEEPSEEK_API_KEY="" \
# Fireworks AI
FIREWORKSAI_API_KEY="" FIREWORKSAI_MODEL_LIST="" \
# Google
GOOGLE_API_KEY="" GOOGLE_PROXY_URL="" \
# Groq
GROQ_API_KEY="" GROQ_MODEL_LIST="" GROQ_PROXY_URL="" \
# Minimax
MINIMAX_API_KEY="" \
# Mistral
MISTRAL_API_KEY="" \
# Moonshot
MOONSHOT_API_KEY="" MOONSHOT_PROXY_URL="" \
# Novita
NOVITA_API_KEY="" NOVITA_MODEL_LIST="" \
# Ollama
OLLAMA_MODEL_LIST="" OLLAMA_PROXY_URL="" \
# OpenAI
OPENAI_API_KEY="" OPENAI_MODEL_LIST="" OPENAI_PROXY_URL="" \
# OpenRouter
OPENROUTER_API_KEY="" OPENROUTER_MODEL_LIST="" \
# Perplexity
PERPLEXITY_API_KEY="" PERPLEXITY_PROXY_URL="" \
# Qwen
QWEN_API_KEY="" QWEN_MODEL_LIST="" \
# SiliconCloud
SILICONCLOUD_API_KEY="" SILICONCLOUD_MODEL_LIST="" SILICONCLOUD_PROXY_URL="" \
# Spark
SPARK_API_KEY="" \
# Stepfun
STEPFUN_API_KEY="" \
# Taichu
TAICHU_API_KEY="" \
# TogetherAI
TOGETHERAI_API_KEY="" TOGETHERAI_MODEL_LIST="" \
# Upstage
UPSTAGE_API_KEY="" \
# 01.AI
ZEROONE_API_KEY="" ZEROONE_MODEL_LIST="" \
# Zhipu
ZHIPU_API_KEY=""
USER nextjs
EXPOSE 3210/tcp
CMD \
if [ -n "$PROXY_URL" ]; then \
# Set regex for IPv4
IP_REGEX="^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$"; \
# Set proxychains command
PROXYCHAINS="proxychains -q"; \
# Parse the proxy URL
host_with_port="${PROXY_URL#*//}"; \
host="${host_with_port%%:*}"; \
port="${PROXY_URL##*:}"; \
protocol="${PROXY_URL%%://*}"; \
# Resolve to IP address if the host is a domain
if ! [[ "$host" =~ "$IP_REGEX" ]]; then \
nslookup=$(nslookup -q="A" "$host" | tail -n +3 | grep 'Address:'); \
if [ -n "$nslookup" ]; then \
host=$(echo "$nslookup" | tail -n 1 | awk '{print $2}'); \
fi; \
fi; \
# Generate proxychains configuration file
printf "%s\n" \
'localnet 127.0.0.0/255.0.0.0' \
'localnet ::1/128' \
'proxy_dns' \
'remote_dns_subnet 224' \
'strict_chain' \
'tcp_connect_time_out 8000' \
'tcp_read_time_out 15000' \
'[ProxyList]' \
"$protocol $host $port" \
> "/etc/proxychains/proxychains.conf"; \
fi; \
# Fix DNS resolving issue in Docker Compose, ref https://github.com/lobehub/lobe-chat/pull/3837
if [ -f "/etc/resolv.conf" ]; then \
sudo chmod 666 "/etc/resolv.conf"; \
resolv_conf=$(grep '^nameserver' "/etc/resolv.conf" | awk '{print "nameserver " $2}'); \
printf "%s\n" \
"$resolv_conf" \
> "/etc/resolv.conf"; \
fi; \
# Run migration
node "/app/docker.cjs"; \
if [ "$?" -eq "0" ]; then \
# Run the server
${PROXYCHAINS} node "/app/server.js"; \
fi;
Key changes:
corepack use pnpm
instead of corepack prepare pnpm@latest --activate
to ensure the correct version of pnpm is activated.pnpm i
is used instead of pnpm install
for consistency with the provided Dockerfile.This should resolve the issues related to setting up the npm registry and installing dependencies using corepack and pnpm [2][3].
To continue talking to Dosu, mention @dosu.
是网络问题,谢谢!
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
It's a network problem, thank you!
✅ @yincangshiwei
This issue is closed, If you have any questions, you can comment and reply.\ 此问题已经关闭。如果您有任何问题,可以留言并回复。
📦 部署环境
Docker
📌 软件版本
all
💻 系统环境
Other Linux
🌐 浏览器
Chrome
🐛 问题描述
dockerfile打包的时候会提示下面错误: Dockerfile:52
51 | 52 | >>> RUN \ 53 | >>> # If you want to build docker in China, build with --build-arg USE_CN_MIRROR=true 54 | >>> if [ "${USE_CN_MIRROR:-false}" = "true" ]; then \ 55 | >>> export SENTRYCLI_CDNURL="https://npmmirror.com/mirrors/sentry-cli"; \ 56 | >>> npm config set registry "https://registry.npmmirror.com/"; \ 57 | >>> fi \ 58 | >>> # Set the registry for corepack 59 | >>> && export COREPACK_NPM_REGISTRY=$(npm config get registry | sed 's/\/$//') \ 60 | >>> # Enable corepack 61 | >>> && corepack enable \ 62 | >>> # Use pnpm for corepack 63 | >>> && corepack use pnpm \ 64 | >>> # Install the dependencies 65 | >>> && pnpm i \ 66 | >>> # Add sharp dependencies 67 | >>> && mkdir -p /deps \ 68 | >>> && pnpm add sharp --prefix /deps 69 |
ERROR: failed to solve: process "/bin/sh -c if [ \"${USE_CN_MIRROR:-false}\" = \"true\" ]; then export SENTRYCLI_CDNURL=\"https://npmmirror.com/mirrors/sentry-cli\"; npm config set registry \"https://registry.npmmirror.com/\"; fi && export COREPACK_NPM_REGISTRY=$(npm config get registry | sed 's/\/$//') && corepack enable && corepack use pnpm && pnpm i && mkdir -p /deps && pnpm add sharp --prefix /deps" did not complete successfully: exit code: 1
📷 复现步骤
No response
🚦 期望结果
No response
📝 补充信息
No response