首页 > 解决方案 > 为什么 docker run 有效,但同一图像的 docker-compose 无效?

问题描述

我尝试rails new testapp使用 docker 运行应用程序。
当我运行它时run -dp 3000:3000 -v "$(pwd):/app" testapp它工作正常,但是当我尝试运行它时,docker-compose up我得到:

web_1  | Could not locate Gemfile or .bundle/ directory
testapp_web_1 exited with code 10

知道为什么吗?

Dockerfile:

FROM ruby:2.7.2
WORKDIR /app
COPY Gemfile Gemfile.lock ./
RUN bundle install
COPY . .
CMD ["rails", "server", "-b", "0.0.0.0"]

码头工人-compose.yml:

version: "3.8"

services:
  web:
    build: .
    volumes:
      - ./app:/app
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    ports: 
      - 3000:3000

标签: ruby-on-railsdockerdocker-compose

解决方案


推荐阅读