我正在为Rails现有应用程序配置Docker,并且在运行Local Host时我的错误低于错误:3000。
迁移正在等待。要解决此问题,请运行:bin/rake db:migrate rails_env = development
如何设置耙子DB:在Docker中迁移 docker-compose yml文件
version: '3'
volumes:
postgres_data: {}
services:
redis:
image: redis
command: redis-server
ports:
- "6379:6379"
app:
build:
context: .
dockerfile: /Users/admin/git/generic/deviceapp/docker/app/Dockerfile
depends_on:
- db
db:
image: postgres
volumes:
- postgres_data:/var/lib/postgresql/data
web:
build:
context: .
dockerfile: /Users/admin/git/generic/deviceapp/docker/web/Dockerfile
depends_on:
- app
ports:
- 80:80
数据库yml文件
development:
adapter: postgresql
encoding: unicode
database: Myapp
pool: 5
username: san
password: test@123
host: db
dockerfile
FROM ruby:2.5.0
ENV RAILS_ROOT /Users/admin/git/generic/Myapplication
ENV REDIS_URL=redis://redis:6379/0
RUN mkdir -p $RAILS_ROOT
# Set working directory
WORKDIR $RAILS_ROOT
# Setting env up
ENV RAILS_ENV='development'
ENV RACK_ENV='development'
# Adding gems
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
RUN bundle install
# Adding project files
COPY . .
RUN gem install bundler
RUN bundle install
COPY . .
EXPOSE 3000
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb", "development", "-
b", "tcp://0.0.0.0:3000"]
干草,就我而言,我解决了这个问题,告诉docker在 docker-compose.yml
中执行一些bash命令。喜欢:
在您的Docker-Compose中:
# your_app_path/docker-compose.yml
...
web:
build:
...
command: bash -c "build-scripts/container/web"
...
当您的Docker'UPS'时,build-scripts/container/web
将被执行。
您的Dockerfile
,将在docker-compose build
上调用,您不应在此文件中执行命令。
创建build-scripts/container/web
,其中此内容:
#!/bin/bash
bundle check || bundle install
bundle exec rake db:setup &&
bundle exec rails s -p 3000 -b '0.0.0.0' -P /tmp/rails.pid
您可以选择将rake db:setup
交换为rake db:migrate
或类似的东西。