0

I have a problem with creating folders and files within a docker container. I have a Ruby and Hanami web app deployed using Dockerfile and docker-compose yaml. Here is the content of both files for reference.

Dockerfile:

    FROM ruby:2.7.5-bullseye

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

    RUN bundle config --global frozen 1

    RUN adduser --disabled-login app_owner

    USER app_owner

    WORKDIR /usr/src/app

    COPY --chown=app_owner Gemfile Gemfile.lock ./
    COPY --chown=app_owner . ./

    RUN gem install bundler:1.17.3
    RUN bundle install

    ENV HANAMI_HOST=0.0.0.0
    ENV HANAMI_ENV=production

    EXPOSE 2300

docker-compose.yml:

version: '3'
services:
  postgres:
    image: postgres
    restart: unless-stopped
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=${POSTGRES_DB}
    ports:
      - 5432
    volumes: 
      - postgres_staging:/var/lib/postgresql/data

  web:
    build: .
    restart: unless-stopped
    command: >
      bash -c "bundle exec hanami db migrate
      && bundle exec rake initial_settings:add_default_language
      && bundle exec rake initial_settings:add_session_validity
      && bundle exec rake import_user:create
      && bundle exec rake super_admin:create
      && bundle exec rake create_parser_rules:start
      && bundle exec hanami assets precompile
      && cp -r apps/myapp/assets/webfonts public/webfonts
      && cp -r apps/myapp/assets/webfonts public/assets/webfonts
      && cp -r apps/myapp/assets/images/sort*.png public/assets
      && cp -r apps/myapp/assets/images/sort*.png public
      && cp -r apps/myapp/assets/images/ui-icons*.png public/assets/wordrocket
      && mkdir public/assets/images
      && cp -r apps/myapp/assets/images/sort*.png public/assets/images
      && bundle exec hanami server"
    volumes:
      - ./hanami_log:/usr/src/app/hanami_log
    links:
      - postgres
    depends_on:
      - postgres

  nginx:
    image: nginx:alpine
    restart: unless-stopped
    tty: true
    ports:
      - "${NGINX_PORT}:80"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
    depends_on:
      - web

volumes:
  postgres_staging:
  web:
  nginx:

The docker-compose has some initial commands that need to be run and the ones creating folders and files are failing. For example bundle exec hanami assets precompile fails with: Permission denied @ dir_s_mkdir - /usr/src/app/public

The command created the folder and then copies over some files. I've confirmed this error by omitting the command from docker-compose and then tried running the command manually in the running container. I get the same error.

Is my configuration incorrect?

EDIT: Forgot one important thing: the problem occurs on the client's server running Ubuntu 20.04, while it works without issues on my dev laptop.

Thank you. Seba

Sebastjan Hribar
  • 396
  • 3
  • 13
  • I'm not sure if this should be a answer, but after some more digging I see that this is actually a correct behavior. And I should take care of this before building the image. I need to move those commands (apart from precompile, which will work when the public folder exists) for creating folders and files out of the compose and run them before building. – Sebastjan Hribar Oct 18 '22 at 05:48
  • Also, it's working on my laptop because those folders and files already exists, but are in the gitignore and as such are not available on the server. – Sebastjan Hribar Oct 18 '22 at 05:49

0 Answers0