Docker 入口点总是返回权限被拒绝

时间:2021-05-15 21:45:14

标签: ruby-on-rails ruby linux docker docker-compose

我正在尝试将我的网络应用程序(使用 Ruby on Rails 开发)运行到 docker 容器中,并且我有以下 dockerfile :

FROM ruby:3.0.1-alpine


ENV BUNDLER_VERSION=2.0.2

RUN apk add --update --no-cache \
      binutils-gold \
      build-base \
      curl \
      file \
      g++ \
      gcc \
      git \
      less \
      libstdc++ \
      libffi-dev \
      libc-dev \
      linux-headers \
      libxml2-dev \
      libxslt-dev \
      libgcrypt-dev \
      make \
      netcat-openbsd \
      nodejs \
      openssl \
      pkgconfig \
      postgresql-dev \
      #python \
      tzdata \
      yarn

RUN gem install bundler -v "$(grep -A 1 "BUNDLED WITH" Gemfile.lock | tail -n 1)"

RUN gem update --system

WORKDIR /app

# COPY Gemfile Gemfile.lock ./
COPY Gemfile ./

# RUN bundle config build.nokogiri --use-system-libraries

RUN bundle check || bundle install

COPY package.json yarn.lock ./

RUN yarn install --check-files

COPY . ./.

# RUN [ "chown", "$USER", "./entrypoints/docker-entrypoint.sh"]
RUN ["chmod", "-R", "+x", "entrypoints/docker-entrypoint.sh"]

ENTRYPOINT ["sh", "entrypoints/docker-entrypoint.sh"]

使用以下 docker-compose 文件:

version: '3.4'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    depends_on:
      - database
      - redis
    ports:
      - "3000:3000"
    volumes:
      - .:/app
      - gem_cache:/usr/local/bundle/gems
      - node_modules:/app/node_modules
    env_file: .env
    environment:
      RAILS_ENV: development

  database:
    image: postgres:12.1
    volumes:
      - db_data:/var/lib/postgresql/data
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql

  redis:
    image: redis:5.0.7

  sidekiq:
    build:
      context: .
      dockerfile: Dockerfile
    depends_on:
      - app
      - database
      - redis
    volumes:
      - .:/app
      - gem_cache:/usr/local/bundle/gems
      - node_modules:/app/node_modules
    env_file: .env
    environment:
      RAILS_ENV: development
    entrypoint: ./entrypoints/sidekiq-entrypoint.sh

volumes:
  gem_cache:
  db_data:
  node_modules:

我的问题是当在图像起点触发“入口点”时,我总是得到 app_1 | /bin/sh: can't open 'entrypoints/docker-entrypoint.sh': Permission denied

如您所见,我将文件的权限更改为我的 docker build 以便能够执行它,但这并不能解决我的问题...

我在互联网上搜索过有关此问题的所有帖子,对于我看到的所有帖子,chmod 已解决此类问题,因此,经过大约 2 小时的“密集”网络搜索后,我需要您的帮助^^

注意: docker-entrypoint.sh 文件只包含:

#!/bin/sh

set -e

if [ -f tmp/pids/server.pid ]; then
  rm tmp/pids/server.pid
fi

bundle exec rails s -b 0.0.0.0

预先感谢您的帮助!

Br

编辑:sidekiq-entrypoint.sh 文件中指定的 docker-compose 存在同样的问题。

2 个答案:

答案 0 :(得分:0)

试试下面的方法

BUG:重置入口点以覆盖基础映像。

入口点 []

CMD 入口点/docker-entrypoint.sh

或者甚至更好地尝试启动服务器。只是为了看看不运行脚本是否有效

CMD bundle exec rails s -b 0.0.0.0

答案 1 :(得分:0)

您能否尝试使用 RUN ["chmod", "-R", "+x", "./entrypoints/docker-entrypoint.sh"] 代替 RUN ["chmod", "-R", "+x", "entrypoints/docker-entrypoint.sh"] 并告诉我们。