【问题标题】:Files which generated through docker-compose run web rails g doesn't create通过 docker-compose run web rails g 生成的文件不会创建
【发布时间】:2021-03-09 16:14:24
【问题描述】:

我有一个项目使用docker-compose 为开发人员提供环境。该应用程序在 docker-compose build 命令上运行良好,在 docker-compose up 命令上运行在 0.0.0.0:3000 上。当我尝试运行命令docker-compose run web rails g uploaderdocker-compose run web rails g migration 时,它会在控制台中显示它们已成功创建,但是当我检查项目时没有文件。

这是我的 Dockerfile:

# Base image
FROM ruby:2.7.0


# Set enviroment variables in docker
ENV INSTALL_PATH=/app \
    RAILS_ENV=production \
    RACK_ENV=$RAILS_ENV \
    RAILS_LOG_TO_STDOUT=true \
    RAILS_SERVE_STATIC_FILES=true \
    SECRET_KEY_BASE=ad187ccccdf25beb51568211a26b0bff237385d79df37e08151acda85266f9a469f37926450ba18d9362ec5e83d1b612c09368bc59dc895cb5ce2798a3ab456b

RUN env

# Ensure gems are cached and only get updated when they change. This will
# drastically increase build times when your gems do not change.
ADD Gemfile* $INSTALL_PATH/

RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
    && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
    && apt-get update \
    && apt-get install -qq -y build-essential nodejs libpq-dev cron htop vim sqlite3 yarn imagemagick netcat --fix-missing --no-install-recommends \
    && cd $INSTALL_PATH; bundle install --jobs 20 --retry 5

WORKDIR $INSTALL_PATH
ADD . .
RUN mv config/database.docker.yml config/database.yml \
    # Fix windows line ending from windows runners
    && find ./ -type f -exec sed -i 's/\r$//' {} + \
    && chmod +x docker/* \
    && yarn install --check-files \
    && RAILS_ENV=$RAILS_ENV bundle exec rails assets:precompile \
    && chown -R nobody:nogroup $INSTALL_PATH
USER nobody

# Expose a volume so that nginx will be able to read in assets in production.
VOLUME ["$INSTALL_PATH/public"]

EXPOSE 3000
CMD ["docker/startup.sh"]

这是我的 docker-compose.yml:

version: '2'

volumes:
  database_data:
    driver: local
  web_rails_public: {}

services:
  web:
    restart: always
    image: eu.gcr.io/academic-ivy-225422/joystree_web
    container_name: joystree_web_app_container
    build: .
    volumes:
      - web_rails_public:/app/public
    env_file:
      - '.env.web'
    ports:
      - "3000:3000"
    links:
      - "database:database"
    depends_on:
      - database

  database:
    restart: always
    container_name: joystree_postgres_container
    image: postgres:11
    env_file:
      - '.env.db'
    ports:
      - "5432:5432"
    volumes:
      - database_data:/var/lib/postgresql/data

【问题讨论】:

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


    【解决方案1】:

    我遇到了同样的问题,按照以下步骤解决了:

    1 - 在Dockerfile 中添加闲置行,以便能够创建新文件:

    RUN mkdir /home/web \ 
    && chown $(id -un):$(id -gn) /home/web
    
    WORKDIR /home/web
    

    2 - 在docker-compose.yml web 中的音量应该是.:/home/web 或者和你在 mkdir 中调用的一样

    web:
        volumes:
          - .:/home/web
    

    希望也能解决你的问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-22
      • 2020-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多