【问题标题】:ActiveRecord::AdapterNotSpecified: 'development' database is not configured. Available: []ActiveRecord::AdapterNotSpecified: \'development\' 数据库未配置。可用的: []
【发布时间】:2022-08-19 03:19:27
【问题描述】:

我正在尝试使用 docker compose 在 Rails 中设置我的开发环境。得到一个错误说

ActiveRecord::AdapterNotSpecified: \'development\' database is not configured. Available: []

Dockerfile:

# syntax=docker/dockerfile:1
FROM ruby:2.5.8

RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
RUN apt-get install cron -y
RUN apt-get install vim -y
RUN export EDITOR=\"/usr/bin/vim\"

RUN addgroup deploy && adduser --system deploy && adduser deploy deploy
USER deploy

WORKDIR /ewagers

RUN (crontab -l 2>/dev/null || true; echo \"*/5 * * * * /config/schedule.rb -with args\") | crontab -

COPY Gemfile .
COPY Gemfile.lock .

RUN gem install bundler -v 2.2.27

RUN bundle install

COPY . .

USER root

COPY docker-entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/docker-entrypoint.sh

COPY wait-for-it.sh /usr/bin/
RUN chmod +x /usr/bin/wait-for-it.sh

RUN chown -R deploy *

RUN chmod 644 app
RUN chmod u+x app

RUN whenever --update-crontab ewagers --set environment=production

COPY config/database.example.yml ./config/database.yml

RUN mkdir data

ARG RAILS_MASTER_KEY
RUN printenv

EXPOSE 3000

# Configure the main process to run when running the image
CMD [\"rails\", \"server\", \"-b\", \"0.0.0.0\"]

数据库.example.yml:

# database.yml

default: &default
  adapter: postgresql
  encoding: unicode
  host: db
  username: postgres
  password: ewagers
  pool: 5

development:
  <<: *default
  database: postgres

码头工人撰写:

version: \"3.9\"

services:
  app:
    build: .
    command: docker-entrypoint.sh
    ports:
      - 4000:3000
    environment:
      DB_URL: postgres://db/ewagers_dev # db is host, ewagers_dev is db name
      RAILS_ENV: development
    volumes:
      - .:/ewagers # mapping our current directory to ewagers directory in the container
      # - ewagers-sync:/ewagers:nocopy
    image: ksun/ewagers:latest
    depends_on:
      - db
  db:
    image: postgres:12
    volumes: 
      - ewagers_postgres_volume:/var/lib/postgresql/data # default storage location for postgres
    environment:
      POSTGRES_PASSWORD: ewagers
    ports: 
      - 5432:5432 # default postgres port
volumes: # we specify a volume so postgres does not write data to temporary db of its container
  ewagers_postgres_volume:

我仔细检查了缩进和间距,完成了 docker build 以确保 database.example.yml 被复制到 database.yml。但是,它似乎甚至无法在 database.yml 中找到我的开发配置。

有趣的是,如果我的 database.example.yml 中有什么并在本地创建一个具有相同内容的 database.yml 文件,它将起作用。但如果没有它,它应该可以工作,因为我正在将 database.example.yml 复制到 dockerfile 中的 databse.yml 。

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


    【解决方案1】:

    我很抱歉提出一个问题作为答案。我没有足够的声望点来发表评论。你能弄清楚吗?我有同样的问题。谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-13
      • 1970-01-01
      • 1970-01-01
      • 2018-12-03
      • 2017-03-27
      • 1970-01-01
      • 2020-11-25
      • 1970-01-01
      相关资源
      最近更新 更多