yunyun_engineer
@yunyun_engineer (yunyun)

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

【Docker +MySQL +M1チップ】docker-compose up実行後ActiveRecord::NoDatabaseError

Q&A

Closed

環境

ruby 2.6.5
rails 6
MySQL
M1チップ搭載macOS

解決したいこと

docker-compose up実行後

ActiveRecord::NoDatabaseError
(下記エラー画像参照)

初学者です。データベースは削除していませんが、よくわかりません。
よろしくお願いします。

発生している問題・エラー

a31e93a0f42fc2d13fe85059b06cd611.png

Docker Compose is now in the Docker CLI, try `docker compose up`

fridge_app_db_1 is up-to-date
Starting fridge_app_web_1 ... done
Attaching to fridge_app_db_1, fridge_app_web_1
db_1   | 2021-06-21 08:17:49+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.6.51-1debian9 started.
db_1   | 2021-06-21 08:17:50+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db_1   | 2021-06-21 08:17:50+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.6.51-1debian9 started.
db_1   | 2021-06-21 08:17:51 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1   | 2021-06-21 08:17:51 0 [Note] /usr/sbin/mysqld (mysqld 5.6.51) starting as process 1 ...
db_1   | 2021-06-21 08:17:51 1 [Warning] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
db_1   | 2021-06-21 08:17:51 1 [Note] Plugin 'FEDERATED' is disabled.
db_1   | 2021-06-21 08:17:51 1 [Note] InnoDB: Using atomics to ref count buffer pool pages
db_1   | 2021-06-21 08:17:51 1 [Note] InnoDB: The InnoDB memory heap is disabled
db_1   | 2021-06-21 08:17:51 1 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
db_1   | 2021-06-21 08:17:51 1 [Note] InnoDB: Memory barrier is not used
db_1   | 2021-06-21 08:17:51 1 [Note] InnoDB: Compressed tables use zlib 1.2.11
db_1   | 2021-06-21 08:17:51 1 [Note] InnoDB: Using Linux native AIO
db_1   | 2021-06-21 08:17:51 1 [Note] InnoDB: Using CPU crc32 instructions
db_1   | 2021-06-21 08:17:51 4004471b80 InnoDB: Error: Linux Native AIO interface is not supported on this platform. Please check your OS documentation and install appropriate binary of InnoDB.
db_1   | InnoDB: You can disable Linux Native AIO by setting innodb_use_native_aio = 0 in my.cnf
db_1   | 2021-06-21 08:17:51 1 [Warning] InnoDB: Linux Native AIO disabled.
db_1   | 2021-06-21 08:17:51 1 [Note] InnoDB: Initializing buffer pool, size = 128.0M
db_1   | 2021-06-21 08:17:51 1 [Note] InnoDB: Completed initialization of buffer pool
db_1   | 2021-06-21 08:17:51 1 [Note] InnoDB: Highest supported file format is Barracuda.
db_1   | 2021-06-21 08:17:51 1 [Note] InnoDB: 128 rollback segment(s) are active.
db_1   | 2021-06-21 08:17:51 1 [Note] InnoDB: 5.6.51 started; log sequence number 1626017
db_1   | 2021-06-21 08:17:52 1 [Note] RSA private key file not found: /var/lib/mysql//private_key.pem. Some authentication plugins will not work.
db_1   | 2021-06-21 08:17:52 1 [Note] RSA public key file not found: /var/lib/mysql//public_key.pem. Some authentication plugins will not work.
db_1   | 2021-06-21 08:17:52 1 [Note] Server hostname (bind-address): '*'; port: 3306
db_1   | 2021-06-21 08:17:52 1 [Note] IPv6 is available.
db_1   | 2021-06-21 08:17:52 1 [Note]   - '::' resolves to '::';
db_1   | 2021-06-21 08:17:52 1 [Note] Server socket created on IP: '::'.
db_1   | 2021-06-21 08:17:52 1 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
db_1   | 2021-06-21 08:17:52 1 [Warning] 'proxies_priv' entry '@ root@b065865994ab' ignored in --skip-name-resolve mode.
db_1   | 2021-06-21 08:17:52 1 [Note] Event Scheduler: Loaded 0 events
db_1   | 2021-06-21 08:17:52 1 [Note] /usr/sbin/mysqld: ready for connections.
db_1   | Version: '5.6.51'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
web_1  | => Booting Puma
web_1  | => Rails 6.0.3.6 application starting in development 
web_1  | => Run `rails server --help` for more startup options
web_1  | Puma starting in single mode...
web_1  | * Version 3.12.6 (ruby 2.6.5-p114), codename: Llamas in Pajamas
web_1  | * Min threads: 5, max threads: 5
web_1  | * Environment: development
web_1  | * Listening on tcp://0.0.0.0:3000
web_1  | Use Ctrl-C to stop
web_1  | Started GET "/" for 172.18.0.1 at 2021-06-21 12:05:06 +0000
web_1  | Cannot render console from 172.18.0.1! Allowed networks: 127.0.0.0/127.255.255.255, ::1
web_1  | Started GET "/" for 172.18.0.1 at 2021-06-21 12:05:09 +0000
web_1  | Cannot render console from 172.18.0.1! Allowed networks: 127.0.0.0/127.255.255.255, ::1
web_1  |   
web_1  | ActiveRecord::NoDatabaseError (Unknown database 'fridge_app_development'):
web_1  |   
web_1  | activerecord (6.0.3.6) lib/active_record/connection_adapters/mysql2_adapter.rb:28:in `rescue in mysql2_connection'
web_1  | activerecord (6.0.3.6) lib/active_record/connection_adapters/mysql2_adapter.rb:14:in `mysql2_connection'
web_1  | activerecord (6.0.3.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:887:in `new_connection'
web_1  | activerecord (6.0.3.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:931:in `checkout_new_connection'
web_1  | activerecord (6.0.3.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:910:in `try_to_checkout_new_connection'
web_1  | activerecord (6.0.3.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:871:in `acquire_connection'
web_1  | activerecord (6.0.3.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:593:in `checkout'
web_1  | activerecord (6.0.3.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:437:in `connection'
web_1  | activerecord (6.0.3.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:1119:in `retrieve_connection'
web_1  | activerecord (6.0.3.6) lib/active_record/connection_handling.rb:221:in `retrieve_connection'
web_1  | activerecord (6.0.3.6) lib/active_record/connection_handling.rb:189:in `connection'
web_1  | activerecord (6.0.3.6) lib/active_record/migration.rb:562:in `call'
web_1  | actionpack (6.0.3.6) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
web_1  | activesupport (6.0.3.6) lib/active_support/callbacks.rb:101:in `run_callbacks'
web_1  | actionpack (6.0.3.6) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
web_1  | actionpack (6.0.3.6) lib/action_dispatch/middleware/executor.rb:14:in `call'
web_1  | actionpack (6.0.3.6) lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
web_1  | actionpack (6.0.3.6) lib/action_dispatch/middleware/debug_exceptions.rb:32:in `call'
web_1  | web-console (4.1.0) lib/web_console/middleware.rb:132:in `call_app'
web_1  | web-console (4.1.0) lib/web_console/middleware.rb:19:in `block in call'
web_1  | web-console (4.1.0) lib/web_console/middleware.rb:17:in `catch'
web_1  | web-console (4.1.0) lib/web_console/middleware.rb:17:in `call'
web_1  | actionpack (6.0.3.6) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
web_1  | railties (6.0.3.6) lib/rails/rack/logger.rb:37:in `call_app'
web_1  | railties (6.0.3.6) lib/rails/rack/logger.rb:26:in `block in call'
web_1  | activesupport (6.0.3.6) lib/active_support/tagged_logging.rb:80:in `block in tagged'
web_1  | activesupport (6.0.3.6) lib/active_support/tagged_logging.rb:28:in `tagged'
web_1  | activesupport (6.0.3.6) lib/active_support/tagged_logging.rb:80:in `tagged'
web_1  | railties (6.0.3.6) lib/rails/rack/logger.rb:26:in `call'
web_1  | sprockets-rails (3.2.2) lib/sprockets/rails/quiet_assets.rb:13:in `call'
web_1  | actionpack (6.0.3.6) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
web_1  | actionpack (6.0.3.6) lib/action_dispatch/middleware/request_id.rb:27:in `call'
web_1  | rack (2.2.3) lib/rack/method_override.rb:24:in `call'
web_1  | rack (2.2.3) lib/rack/runtime.rb:22:in `call'
web_1  | activesupport (6.0.3.6) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
web_1  | actionpack (6.0.3.6) lib/action_dispatch/middleware/executor.rb:14:in `call'
web_1  | actionpack (6.0.3.6) lib/action_dispatch/middleware/static.rb:126:in `call'
web_1  | rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
web_1  | actionpack (6.0.3.6) lib/action_dispatch/middleware/host_authorization.rb:82:in `call'
web_1  | webpacker (4.3.0) lib/webpacker/dev_server_proxy.rb:23:in `perform_request'
web_1  | rack-proxy (0.6.5) lib/rack/proxy.rb:57:in `call'
web_1  | railties (6.0.3.6) lib/rails/engine.rb:527:in `call'
web_1  | puma (3.12.6) lib/puma/configuration.rb:227:in `call'
web_1  | puma (3.12.6) lib/puma/server.rb:706:in `handle_request'
web_1  | puma (3.12.6) lib/puma/server.rb:476:in `process_client'
web_1  | puma (3.12.6) lib/puma/server.rb:334:in `block in run'
web_1  | puma (3.12.6) lib/puma/thread_pool.rb:135:in `block in spawn_thread'

該当するソースコード

FROM ruby:2.6.5

RUN apt-get update && apt-get install -y curl apt-transport-https wget && \
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

RUN apt-get update -qq && apt-get install -y nodejs yarn
RUN mkdir /fridge_app
WORKDIR /fridge_app
COPY Gemfile Gemfile.lock /fridge_app/
ENV BUNDLER_VERSION 2.1.4
RUN gem update --system \
    && gem install bundler -v $BUNDLER_VERSION \
    && bundle install -j 4
COPY . /fridge_app

RUN yarn install --check-files
RUN bundle exec rails webpacker:install

ENV PATH $PATH:/usr/local/src/bin

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

CMD ["rails", "server", "-b", "0.0.0.0"]
docker-compose.yml
version: '3'
services:
  db:
    image: mysql:5.6
    platform: linux/x86_64
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: root
    ports:
      - "3306:3306"
    volumes:
      - ./tmp/db:/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'"
    volumes:
      - .:/fridge_app
    ports:
      - "3000:3000"
    depends_on:
      - db
0

No Answers yet.

Your answer might help someone💌