Docker:运行脚本:错误:无法锁定数据库:权限被拒绝

时间:2020-06-01 18:40:24

标签: postgresql docker docker-compose

你好,我正在尝试运行一个脚本,以便在连接postgres后立即启动我的yarn开发:

until psql -c '\l'; do
  echo >&2 "$(date +%Y%m%dt%H%M%S) Postgres is unavailable - sleeping"
  sleep 1
done
echo >&2 "$(date +%Y%m%dt%H%M%S) Postgres is up - executing command"

exec ${@}

docker文件:

    #building code
    FROM node:lts-alpine

    RUN mkdir -p /home/node/api && chown -R node:node /home/node/api

    WORKDIR /home/node/api

    COPY ormconfig.json .env package.json yarn.* ./

    USER node

    RUN yarn

    COPY --chown=node:node . .

    RUN apk add --no-cache openssl

    COPY wait-pg.sh ./
    RUN chmod +x /wait-pg.sh
    ENTRYPOINT ["/wait-pg.sh"]

    EXPOSE 4000

    CMD ["yarn", "dev"]

泊坞窗撰写:

version: '3.7'
services:
  db-pg:
    image: postgres:12
    container_name: db-pg
    ports:
      - '${DB_PORT}:5432'
    environment:
      ALLOW_EMPTY_PASSWORD: 'no'
      POSTGRES_USER: ${DB_USER}
      POSTGRES_PASSWORD: ${DB_PASS}
      POSTGRES_DB: ${DB_NAME}
    volumes:
      - ci-postgres-data:/data

  ci-api:
    build: .
    container_name: ci-api
    volumes:
      - .:/home/node/api
      - /home/node/api/node_modules
    ports:
      - '${SERVER_PORT}:${SERVER_PORT}'
    depends_on:
      - db-pg
    command: ['./wait-pg.sh', 'yarn', 'dev']
    logging:
      driver: 'json-file'
      options:
        max-size: '10m'
        max-file: '5'

volumes:
  ci-postgres-data:

并收到此错误:

--->在c5add5098b70中运行错误:无法锁定数据库: 权限被拒绝错误:无法打开apk数据库:权限 拒绝的错误:服务'ci-api'生成失败:命令'/ bin / sh -c apk add --no-cache openssl'返回了非零代码:99

1 个答案:

答案 0 :(得分:0)

您收到此错误,因为您要使用的节点用户没有运行该命令的权限。 将用户定义移至命令之后,如下所示:

  #building code
    FROM node:lts-alpine

    RUN mkdir -p /home/node/api && chown -R node:node /home/node/api
    WORKDIR /home/node/api
    COPY ormconfig.json .env package.json yarn.* ./

    RUN yarn
    COPY --chown=node:node . .
    RUN apk add --no-cache openssl
    COPY wait-pg.sh .
    RUN chmod +x ./wait-pg.sh

    USER node



    ENTRYPOINT ["./wait-pg.sh"]
    EXPOSE 4000
    CMD ["yarn", "dev"]