Skip to content

数据库连接提示“你没有权限访问数据库连接” #2425

@ghoulich

Description

@ghoulich

Describe the bug
我修改了你们官方的Dockerfile,自己构建了v1.10.0版本的Teable镜像,镜像中包含postgres,在启动容器后,在自己的空间中建立数据库和表格,打开表格的设计页面,发现数据库连接提示“你没有权限访问数据库连接”!

To Reproduce
复现步骤如下:

  1. 创建Dockerfile
ARG NODE_VERSION=20.9.0
ARG BUILD_VERSION="1.10.0"

###################################################################
# Stage 1: Install all workspaces (dev)dependencies               #
#          and generates node_modules folder(s)                   #
###################################################################

FROM node:${NODE_VERSION}-bookworm AS deps

# set proxy
ARG http_proxy=http://192.168.0.101:18888 \
    https_proxy=http://192.168.0.101:18888 \
    no_proxy=mirrors.tuna.tsinghua.edu.cn,mirrors.aliyun.com,ubuntu.com,ros.org,developer.download.nvidia.cn,npmmirror.com

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable && pnpm add npm-run-all2 zx -g

RUN apt update && \
    apt install -y git curl wget
RUN git clone https://github.com/teableio/teable.git /workspace-install && \
    cd /workspace-install && \
    git checkout v1.10.0

# Disabling some well-known postinstall scripts
ENV HUSKY=0

WORKDIR /workspace-install

RUN pnpm fetch --registry=https://registry.npmmirror.com
RUN pnpm install --prefer-offline --frozen-lockfile
RUN pnpm -F @teable/db-main-prisma prisma-generate --schema ./prisma/postgres/schema.prisma

###################################################################
# Stage 2: Build the app                                          #
###################################################################

FROM deps AS builder

ARG INTEGRATION_TEST
ARG BUILD_VERSION
ARG ENABLE_CSP=true
ARG SENTRY_ENABLED=true
ARG SENTRY_TRACING=true

ENV NODE_ENV=production \
    NEXT_BUILD_ENV_CSP=${ENABLE_CSP} \
    NEXT_BUILD_ENV_TYPECHECK=false \
    NEXT_BUILD_ENV_LINT=false \
    NEXT_BUILD_ENV_SENTRY_ENABLED=${SENTRY_ENABLED} \
    NEXT_BUILD_ENV_SENTRY_TRACING=${SENTRY_TRACING}

WORKDIR /app

COPY --from=deps --link /workspace-install ./

RUN set -ex; \
        echo "\nNEXT_PUBLIC_BUILD_VERSION=\"${BUILD_VERSION}\"" >> apps/nextjs-app/.env; \
# Distinguish whether it is an integration test operation
        if [ -n "$INTEGRATION_TEST" ]; then \
              pnpm -F "./packages/**" run build; \
        else \
              NODE_OPTIONS=--max-old-space-size=8192 pnpm g:build; \
        fi


##################################################################
# Stage 3: Post Builder                                          #
##################################################################

FROM builder as post-builder

ENV NODE_ENV=production

WORKDIR /app

ARG UPLOAD_ASSETS_LIST=""

RUN set -ex; \
        rm -fr node_modules; \
        pnpm nuke:node_modules; \
        chmod +x ./scripts/post-build-cleanup.mjs; \
        zx ./scripts/post-build-cleanup.mjs; \
        pnpm install --prod --prefer-offline --frozen-lockfile; \
        pnpm -F @teable/db-main-prisma prisma-generate --schema ./prisma/postgres/schema.prisma

RUN set -ex; \
        apt-get update; \
        apt-get install -y --no-install-recommends rsync; \
        rm -rf /var/lib/apt/lists/*; \
        chmod +x ./scripts/upload-assets.mjs; \
        zx ./scripts/upload-assets.mjs --list="$UPLOAD_ASSETS_LIST";


##################################################################
# Stage 4: Extract a minimal image from the build                #
##################################################################

FROM node:${NODE_VERSION}-bookworm-slim AS runner

# basic envs
SHELL ["/bin/bash", "-c"]
WORKDIR /root
ARG GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" \
    DEBIAN_FRONTEND=noninteractive

# set proxy
ARG http_proxy=http://192.168.0.101:18888 \
    https_proxy=http://192.168.0.101:18888 \
    no_proxy=mirrors.tuna.tsinghua.edu.cn,mirrors.aliyun.com,ubuntu.com,ros.org,developer.download.nvidia.cn,npmmirror.com

# install oh-my-bash
RUN apt update && \
    apt install -y git curl software-properties-common apt-transport-https net-tools telnet procps python3 python3-pip && \
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/ohmybash/oh-my-bash/master/tools/install.sh)"

# setup environment
ENV TZ=UTC \
    NODE_ENV=production \
    PORT=3000\
    NEXTJS_DIR=apps/nextjs-app \
    PNPM_HOME="/pnpm" \
    PATH=/app/packages/db-main-prisma/node_modules/.bin:/usr/lib/postgresql/16/bin:$PNPM_HOME:$PATH \
    PUBLIC_ORIGIN=http://127.0.0.1:3000 \
    POSTGRES_USER=teable \
    POSTGRES_PASSWORD=P@ssw0rd123 \
    POSTGRES_DB=teable \
    POSTGRES_INITDB_ARGS="--encoding=UTF8 --locale=C.UTF-8 --data-checksums" \
    PGDATA=/var/lib/postgresql/data \
    PG_MAJOR=16 \
    PRISMA_DATABASE_URL=postgresql://teable:P@ssw0rd123@127.0.0.1:5432/teable

RUN set -ex; \
        npm install zx -g; \
        corepack enable; \
        apt-get update; \
        apt-get install -y --no-install-recommends \
                curl \
                openssl \
    	; \
    	rm -rf /var/lib/apt/lists/*

# install gosu for a better su+exec command
# https://github.com/tianon/gosu/blob/master/INSTALL.md
ENV GOSU_VERSION 1.17
RUN set -eux; \
# save list of currently installed packages for later so we can clean up
        savedAptMark="$(apt-mark showmanual)"; \
        apt-get update; \
        apt-get install -y --no-install-recommends ca-certificates gnupg wget; \
        rm -rf /var/lib/apt/lists/*; \
        \
        dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
        wget -nv -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
        wget -nv -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \
        \
# verify the signature
        export GNUPGHOME="$(mktemp -d)"; \
        gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
        gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
        gpgconf --kill all; \
        rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
        \
# clean up fetch dependencies
        apt-mark auto '.*' > /dev/null; \
        [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; \
        apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
        \
        chmod +x /usr/local/bin/gosu; \
# verify that the binary works
        gosu --version; \
        gosu nobody true

WORKDIR /app

RUN set -ex; \
        addgroup --system --gid 1001 nodejs; \
        adduser --system --uid 1001 nodejs; \
# Set the correct permission for local cache
        mkdir .assets; \
        mkdir .temporary; \
        chown -R nodejs:nodejs /app

COPY --from=post-builder --chown=nodejs:nodejs /app/apps/nextjs-app/next.config.js \
        /app/apps/nextjs-app/next-i18next.config.js \
        /app/apps/nextjs-app/package.json \
        /app/apps/nextjs-app/.env \
        ./apps/nextjs-app/

COPY --from=post-builder --chown=nodejs:nodejs /app/apps/nextjs-app/.next ./apps/nextjs-app/.next
COPY --from=post-builder --chown=nodejs:nodejs /app/apps/nextjs-app/node_modules ./apps/nextjs-app/node_modules
COPY --from=post-builder --chown=nodejs:nodejs /app/apps/nextjs-app/public ./apps/nextjs-app/public

COPY --from=post-builder --chown=nodejs:nodejs /app/apps/nestjs-backend/dist ./apps/nestjs-backend/dist
COPY --from=post-builder --chown=nodejs:nodejs /app/apps/nestjs-backend/node_modules ./apps/nestjs-backend/node_modules
COPY --from=post-builder --chown=nodejs:nodejs /app/apps/nestjs-backend/package.json ./apps/nestjs-backend/

# mv it is necessary
COPY --from=builder --chown=nodejs:nodejs /app/packages/common-i18n/ ./packages/common-i18n/

COPY --from=post-builder --chown=nodejs:nodejs /app/packages ./packages
COPY --from=post-builder --chown=nodejs:nodejs /app/node_modules ./node_modules
COPY --from=post-builder --chown=nodejs:nodejs /app/package.json ./package.json

COPY --from=post-builder --chown=nodejs:nodejs /app/plugins/.next/standalone/plugins ./plugins
COPY --from=post-builder --chown=nodejs:nodejs /app/apps/nestjs-backend/static ./static

COPY --from=deps --chown=nodejs:nodejs /workspace-install/scripts/start.sh ./scripts/start.sh
COPY --from=deps --chown=nodejs:nodejs /workspace-install/scripts/db-migrate.mjs ./scripts/db-migrate.mjs
COPY --from=deps --chown=nodejs:nodejs /workspace-install/scripts/wait-for ./scripts/wait-for

ENV BUILD_VERSION=$BUILD_VERSION

RUN set -ex; \
        npm install -g zx; \
        apt-get update; \
        apt-get install -y --no-install-recommends \
                curl \
                ca-certificates \
                openssl \
                netcat-traditional \
                wget \
    	; \
    	rm -rf /var/lib/apt/lists/*; \
        ln -s /usr/local/lib/node_modules /node_modules

EXPOSE 3000

# install postgres
RUN install -d /usr/share/postgresql-common/pgdg  && \
    curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc && \
    source /etc/os-release && \
    /bin/bash -c "echo 'deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $VERSION_CODENAME-pgdg main' > /etc/apt/sources.list.d/pgdg.list" && \
    apt update && \
    apt install -y postgresql-16 postgresql-16-pgvector postgresql-client-16 && \
    mkdir -pv /docker-entrypoint-initdb.d/
COPY postgres-entrypoint.sh /usr/local/bin/postgres-entrypoint.sh

# install supervisor
RUN apt install -y supervisor
RUN mkdir -pv /var/supervisord/logs && \
    mkdir -pv /var/supervisord/sock && \
    mkdir -pv /var/supervisord/pid

COPY supervisord.conf /etc/supervisor/supervisord.conf
ENTRYPOINT [ "supervisord", "-n", "-c", "/etc/supervisor/supervisord.conf" ]
  1. 构建镜像
docker build -t teable:v1.10.0 .
  1. 启动容器
docker run --detach --rm --name teable --hostname teable -p 3000:3000 -p 5432:5432 -e POSTGRES_HOST=127.0.0.1 -e POSTGRES_PORT=5432 -e POSTGRES_DB=teable -e POSTGRES_USER=teable -e POSTGRES_PASSWORD=P@ssw0rd123 -e PUBLIC_DATABASE_PROXY=10.192.129.130:5432 -e NEXT_ENV_IMAGES_ALL_REMOTE=true teable:v1.10.0
  1. 注册和登陆用户
  2. 创建数据库和表格,进入表格设计页面

Expected behavior
希望能像文档:
https://help.teable.ai/zh/api-doc/sql-query#sql
中描述的一样正确运行

Screenshots

Image

** Client (please complete the following information):**

  • OS: Ubuntu 22.04
  • Browser Chrome
  • Version 127.0.6533.119 (Official Build) (64-bit)

Platform (Please tell us which deployment version you are using)
[eg. teable.ai, docker-standalone, docker-swarm, docker-cluster]

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions