2
2

More than 3 years have passed since last update.

docker-compose run web rails new . --force --no-deps --database=mysql --skip-test --webpackerでエラーが出た

Posted at

docker-compose run web rails new . --force --no-deps --database=mysql --skip-test --webpackerでエラーが出たが、解決できたので今後のために備忘録。

参考URL

登場ファイル

Dockerfile.
FROM ruby:2.6

# install package to docker container
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev \
    && apt-get install apt-transport-https \
    && 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 -y yarn \
    && curl -sL https://deb.nodesource.com/setup_10.x | bash - \
    && apt-get install -y nodejs \
    && mkdir /FANTRA

WORKDIR /FANTRA
COPY Gemfile /FANTRA/Gemfile
COPY Gemfile.lock /FANTRA/Gemfile.lock

COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000

docker-compose.yml
version: '3'
services:
  db:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: password
    ports:
      - '3306:3306'
    command: --default-authentication-plugin=mysql_native_password
    volumes:
      - mysql-data:/var/lib/mysql
  web:
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    environment:
      RAILS_ENV: development
    volumes:
      - .:/FANTRA
      - bundle:/usr/local/bundle
    ports:
      - "3000:3000"
    depends_on:
      - db
    tty: true

volumes:
  mysql-data:
    driver: local
  bundle:
    driver: local
Gemfile.
source 'https://rubygems.org'
gem 'rails', '~>6'
Gemfile.lock
#空白のまま
entrypoint.sh
#!/bin/bash
set -e

# Remove a potentially pre-existing server.pid for Rails.
rm -f /FANTRA/tmp/pids/server.pid

# Then exec the container's main process (what's set as CMD in the Dockerfile).
exec "$@"

エラー

上記のファイル等を用意した上で、rails newをしようとすると、

docker-compose run web rails new . --force --no-deps --database=mysql --skip-test --webpacker

こんなエラーが出てきた

WARNING: Image for service web was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
/usr/bin/entrypoint.sh: line 8: exec: rails: not found

docker-compose buildをしろって言ってくれてるから、実行してみる

docker-compose build

再度、rails newをしてみてみると、またエラー。

/usr/bin/entrypoint.sh: line 8: exec: rails: not found

ここでよく見ると、rails: not foundの文字が、、、、、。
Gemfileに書いてあるやつをbundle installしたらええんちゃう???

docker-compose run web bundle install 

これで無事にrails newコマンドを使うことができました。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2