You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Docker运行Strapi时无法连接Scaleway托管的PostgreSQL数据库

Docker运行Strapi无法连接Scaleway PostgreSQL数据库

我尝试用Docker运行Strapi,但始终无法连接到Scaleway托管的PostgreSQL数据库。相关情况如下:

  • 本地直接执行strapi start启动Strapi,一切正常
  • 在本地和计算实例上,通过命令psql -h xx.xxx.xxx.xx -p xxxxx -U strapi -d strapi都能成功连接数据库,说明连接本身和Strapi均无问题
  • 已确认Docker能正确读取所需环境变量,我使用的容器启动命令为:sudo docker run -p 1337:1337 -p 22092:22092 --env-file .env rg.fr-par.scw.cloud/xxx/xxx

以下是我的Dockerfile:

# Creating multi-stage build for production
FROM node:18-alpine as build
RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev vips-dev git > /dev/null 2>&1
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}

WORKDIR /opt/
COPY package.json package-lock.json ./
RUN npm install -g node-gyp
RUN npm config set fetch-retry-maxtimeout 600000 -g && npm install --only=production
ENV PATH /opt/node_modules/.bin:$PATH
WORKDIR /opt/app
COPY . .
RUN npm run build # strapi build

# Creating final production image
FROM node:18-alpine
RUN apk add --no-cache vips-dev
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/
COPY --from=build /opt/node_modules ./node_modules
WORKDIR /opt/app
COPY --from=build /opt/app ./
ENV PATH /opt/node_modules/.bin:$PATH

RUN chown -R node:node /opt/app
USER node
EXPOSE 1337
CMD ["npm", "run", "start"] # strapi start

内容的提问来源于stack exchange,提问作者Timm Nicolaizik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 20:57:54