Home > Mobile >  permission denied while trying to start rails server in docker
permission denied while trying to start rails server in docker

Time:03-17

I'm trying to run a rails server in a docker image along with a mysql and vue frontend image. I'm using ruby 3 and rails 6. The mysql and frontend image both start without problems. However the rails images doesn't start. I'm on a Macbook Pro with MacOS Monterey and Docker Desktop 4.5.0

this is my docker-compose.yml:

version: "3"
services:
  mysql:
    image: mysql:8.0.21
    command:
      - --default-authentication-plugin=mysql_native_password
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=nauza_backend_development
    ports:
      - "3307:3306"
    volumes:
      - mysql:/var/lib/mysql

  backend:
    build:
      context: nauza-backend
      args:
        UID: ${UID:-1001}
    tty: true
    stdin_open: true
    command:
      bundle exec rails s -p 8080 -b '0.0.0.0'
    volumes:
      - ./nauza-backend:/usr/src/app
      # attach a volume at /bundle to cache gems
      - bundle:/bundle
      # attach a volume at ./node_modules to cache node modules
      - node-modules:/usr/src/app/node_modules
      # attach a volume at ./tmp to cache asset compilation files
      - tmp:/usr/src/app/tmp
    environment:
      - RAILS_ENV=development
    ports:
      - "8080:8080"
    depends_on:
      - mysql
    user: rails
    environment:
      - RAILS_ENV=development
      - MYSQL_HOST=mysql
      - MYSQL_USER=root
      - MYSQL_PASSWORD=root
  frontend:
    build:
      context: nauza-frontend
      args:
        UID: ${UID:-1001}
    volumes:
      - ./nauza-frontend:/usr/src/app
    ports:
      - "3000:3000"
    user: frontend
volumes:
  bundle:
    driver: local
  mysql:
    driver: local
  tmp:
    driver: local
  node-modules:
    driver: local

and this is my Dockerfile:

FROM ruby:3.0.2

ARG UID
RUN adduser rails --uid $UID --disabled-password --gecos ""

ENV APP /usr/src/app
RUN mkdir $APP
WORKDIR $APP

ENV EDITOR=vim

RUN apt-get update \
    && apt-get install -y \
        nmap \
        vim

COPY Gemfile* $APP/
RUN bundle install -j3 --path vendor/bundle

COPY . $APP/

CMD ["rails", "server", "-p", "8080", "-b", "0.0.0.0"]

when I try to start this with docker-compose up on my Mac I get the following error:

/usr/local/lib/ruby/3.0.0/fileutils.rb:253:in `mkdir': Permission denied @ dir_s_mkdir - /usr/src/app/tmp/cache (Errno::EACCES)

Any ideas on how to fix this?

CodePudding user response:

Remove the line - tmp:/usr/src/app/tmp on your Dockerfile.

You don't need to access temp files of your container I would say.

  • Related