Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用docker for rails运行db migrate时出错_Ruby On Rails_Macos_Docker - Fatal编程技术网

Ruby on rails 使用docker for rails运行db migrate时出错

Ruby on rails 使用docker for rails运行db migrate时出错,ruby-on-rails,macos,docker,Ruby On Rails,Macos,Docker,我正试图根据教程为Vue.js和rails API设置一个开发环境 最终,我在尝试运行以下命令时遇到了障碍: docker-compose run backend rails db:create docker-compose run backend bundle exec rails db:create 以下是错误: $ docker-compose run backend rails db:create Starting am-full-stack_db_1_b7f6ee37d2e4 ..

我正试图根据教程为Vue.js和rails API设置一个开发环境

最终,我在尝试运行以下命令时遇到了障碍:

docker-compose run backend rails db:create
docker-compose run backend bundle exec rails db:create
以下是错误:

$ docker-compose run backend rails db:create
Starting am-full-stack_db_1_b7f6ee37d2e4 ... done
Error response from daemon: OCI runtime create failed: 
container_linux.go:348: starting container process caused "exec: 
\"rails\": executable file not found in $PATH": unknown
这是我的文件树

应用程序

autheg后端

autheg前端

docker-compose.yml

version: '3'
services:
  db:
    image: postgres
    ports:
      - "5432"
  backend:
    build:
      context: autheg-backend
      args:
        UID: ${UID:-1001}
    volumes:
      - ./autheg-backend:/usr/src/app
    ports:
      - "8080:8080"
    depends_on:
      - db
    user: rails
  frontend:
    build:
      context: autheg-frontend
      args:
        UID: ${UID:-1001}
    volumes:
      - ./autheg-frontend:/usr/src/app
    ports:
      - "3000:3000"
    user: frontend
version: '3'
services:
  db:
    image: postgres
    ports:
      - "5432"
  backend:
    build:
      context: autheg-backend
      args:
        UID: ${UID:-1001}
    command: bundle exec rails s -p 8080 -b '0.0.0.0'
    volumes:
      - ./autheg-backend:/usr/src/app
    ports:
      - "8080:8080"
    depends_on:
      - db
    user: rails
  frontend:
    build:
      context: autheg-frontend
      args:
        UID: ${UID:-1001}
    volumes:
      - ./autheg-frontend:/usr/src/app
    ports:
      - "3000:3000"
    user: frontend
这是我的docker-compose.yml

version: '3'
services:
  db:
    image: postgres
    ports:
      - "5432"
  backend:
    build:
      context: autheg-backend
      args:
        UID: ${UID:-1001}
    volumes:
      - ./autheg-backend:/usr/src/app
    ports:
      - "8080:8080"
    depends_on:
      - db
    user: rails
  frontend:
    build:
      context: autheg-frontend
      args:
        UID: ${UID:-1001}
    volumes:
      - ./autheg-frontend:/usr/src/app
    ports:
      - "3000:3000"
    user: frontend
version: '3'
services:
  db:
    image: postgres
    ports:
      - "5432"
  backend:
    build:
      context: autheg-backend
      args:
        UID: ${UID:-1001}
    command: bundle exec rails s -p 8080 -b '0.0.0.0'
    volumes:
      - ./autheg-backend:/usr/src/app
    ports:
      - "8080:8080"
    depends_on:
      - db
    user: rails
  frontend:
    build:
      context: autheg-frontend
      args:
        UID: ${UID:-1001}
    volumes:
      - ./autheg-frontend:/usr/src/app
    ports:
      - "3000:3000"
    user: frontend
“docker compose运行后端环境”的结果

PATH=/usr/local/bundle/bin:/usr/local/bundle/gems/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=c88e0c72c584
TERM=xterm
RUBY_MAJOR=2.5
RUBY_VERSION=2.5.3
RUBY_DOWNLOAD_SHA256=1cc9d0359a8ea35fc6111ec830d12e60168f3b9b305a3c2578357d360fcf306f
RUBYGEMS_VERSION=2.7.8
BUNDLER_VERSION=1.17.1
GEM_HOME=/usr/local/bundle
BUNDLE_PATH=/usr/local/bundle
BUNDLE_SILENCE_ROOT_WARNING=1
BUNDLE_APP_CONFIG=/usr/local/bundle
APP=/usr/src/app
HOME=/home/rails

谢谢

这是因为路径不是在Docker容器中设置的,而是在开发/本地计算机上设置的。使用以下命令:

docker-compose run backend rails db:create
docker-compose run backend bundle exec rails db:create

rails开发的备份dockerfile在哪里,如本例所示:-

# Base image:
FROM ruby:2.5

# Install dependencies
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs

# create application directory
RUN mkdir /myapp

# Set our working directory inside the image
WORKDIR /myapp

# Setting env up
ENV RAILS_ENV='development'
ENV RACK_ENV='development'

COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
ADD . /myapp

EXPOSE 3000

CMD [ "bundle", "exec", "puma", "-C", "config/puma.rb" ]

要进行数据库迁移,请使用:

docker-compose run backend bin/rails db:create
# or
docker-compose run backend bundle exec rails db:create
/后端/Dockerfile

FROM ruby:2.5

ARG UID
RUN adduser rails --uid $UID --disabled-password --gecos ""

ENV APP /usr/src/app
RUN mkdir $APP
WORKDIR $APP

COPY Gemfile* $APP/
RUN bundle install -j3 --path vendor/bundle

COPY . $APP/

# Setting env up
ENV RAILS_ENV='development'
ENV RACK_ENV='development'

CMD [ "bundle", "exec", "rails", "server", "-p", "8080", "-b", "0.0.0.0"]
./docker-compose.yml

version: '3'
services:
  db:
    image: postgres
    ports:
      - "5432"
  backend:
    build:
      context: autheg-backend
      args:
        UID: ${UID:-1001}
    volumes:
      - ./autheg-backend:/usr/src/app
    ports:
      - "8080:8080"
    depends_on:
      - db
    user: rails
  frontend:
    build:
      context: autheg-frontend
      args:
        UID: ${UID:-1001}
    volumes:
      - ./autheg-frontend:/usr/src/app
    ports:
      - "3000:3000"
    user: frontend
version: '3'
services:
  db:
    image: postgres
    ports:
      - "5432"
  backend:
    build:
      context: autheg-backend
      args:
        UID: ${UID:-1001}
    command: bundle exec rails s -p 8080 -b '0.0.0.0'
    volumes:
      - ./autheg-backend:/usr/src/app
    ports:
      - "8080:8080"
    depends_on:
      - db
    user: rails
  frontend:
    build:
      context: autheg-frontend
      args:
        UID: ${UID:-1001}
    volumes:
      - ./autheg-frontend:/usr/src/app
    ports:
      - "3000:3000"
    user: frontend
然后

现在,您应该能够通过以下方式查看rails站点: 本地主机:8080(而不是3000)


希望能帮助您入门

docker compose run backend env的输出是什么?@UkuLoskit添加到问题中!我在本教程中看到了同样的情况。瑞奇,你发现了吗?