服务器失败"/>
Docker部署到远程服务器失败
我尝试将 docker 部署到具有 docker 上下文的远程服务器,但它在运行 yarn 构建阶段一直失败并出现此错误(所有先前的步骤都运行正常):
failed to receive status: rpc error: code = Unavailable desc = error reading from server: command [ssh -l root -- <remote-server-ip> docker system dial-stdio] has exited with exit status 255, please make sure the URL is valid, and Docker 18.09 or later is installed on the remote host: stderr=
我有一个容器,里面有 Next.js 项目,我用这个命令部署它:
docker-compose --context remote up -d
我的主机在 MacOS 上,远程主机是带有 docker 20.10.21-0ubuntu1~20.04.2. 的 Ubuntu
这是我的 Dockerfile:
FROM node:18-alpine AS base
# Install dependencies only when needed
FROM base AS deps
# Check to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here:
# Uncomment the following line in case you want to disable telemetry during the build.
ENV NEXT_TELEMETRY_DISABLED 1
RUN yarn build
# If using npm comment out above and use below instead
# RUN npm run build
# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
ENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
ENV NEXT_TELEMETRY_DISABLED 1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
# Automatically leverage output traces to reduce image size
#
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT 3000
CMD ["node", "server.js"]
如果有人反驳这样的问题,我将不胜感激。导致错误的原因可能是什么?
更新
当我运行
ssh -l root -- <remote server ip> docker version
时,它给了我这个输出:
Client:
Version: 20.10.21
API version: 1.41
Go version: go1.18.1
Git commit: 20.10.21-0ubuntu1~20.04.2
Built: Thu Apr 27 05:56:19 2023
OS/Arch: linux/amd64
Context: default
Experimental: true
Server:
Engine:
Version: 20.10.21
API version: 1.41 (minimum version 1.12)
Go version: go1.18.1
Git commit: 20.10.21-0ubuntu1~20.04.2
Built: Thu Apr 27 05:37:01 2023
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.12-0ubuntu1~20.04.1
GitCommit:
runc:
Version: 1.1.4-0ubuntu1~20.04.1
GitCommit:
docker-init:
Version: 0.19.0
GitCommit:
另外,这是我的 docker-compose.yml:
version: "3.9"
services:
agregator:
build: .
container_name: app
ports:
- "3000:3000"
command: ["yarn", "start"]
回答如下:
更多推荐
Docker部署到远程服务器失败
发布评论