docker可执行文件没有在$ PATH中find

试图在正在运行的docker compose容器上运行rails迁移会引发这个错误:

$ docker-compose run webapp rails db:migrate 

错误:无法启动服务webapp:无效的头字段值“oci运行时错误:container_linux.go:247:启动容器进程导致\”exec:\\“rails \\”:可执行文件找不到$ PATH \“\ n”

但是,我可以从容器内部访问导轨:

 $ docker-compose run webapp bash root@3fd3a87275a1:/home/app/webapp# which rails /usr/local/rvm/gems/ruby-2.3.1/bin/rails 

我的容器已经运行,我可以获取页面:

 $ curl http://localhost -i HTTP/1.1 200 OK Content-Type: text/html; charset=utf-8 Transfer-Encoding: chunked Connection: keep-alive Status: 200 OK Cache-Control: max-age=0, private, must-revalidate ETag: W/"b62d4f67b7b823c017534cd9727752cd" X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block X-Content-Type-Options: nosniff X-Runtime: 0.019881 X-Request-Id: eb32ec21-3a8f-4caa-a27b-2e42f0b2bce9 Date: Thu, 15 Dec 2016 15:15:59 GMT X-Powered-By: Phusion Passenger 5.0.29 Server: nginx/1.10.1 + Phusion Passenger 5.0.29 

我如何run rails db:migrate在我的容器中run rails db:migrate

Dockerfile

 FROM phusion/passenger-ruby23 # Set correct environment variables. ENV HOME /root # Use baseimage-docker's init process. CMD ["/sbin/my_init"] # additional packages RUN apt-get update # Active nginx RUN rm -f /etc/service/nginx/down # Install bundle of gems WORKDIR /tmp ADD Gemfile /tmp/ ADD Gemfile.lock /tmp/ RUN bundle install # Copy the nginx template for configuration and preserve environment variables RUN rm /etc/nginx/sites-enabled/default # Add the nginx site and config ADD webapp.conf /etc/nginx/sites-enabled/webapp.conf RUN mkdir /home/app/webapp COPY . /home/app/webapp RUN usermod -u 1000 app RUN chown -R app:app /home/app/webapp WORKDIR /home/app/webapp # Clean up APT when done. RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* EXPOSE 80 

Docker撰写

 version: '2' services: webapp: build: . container_name: myapp working_dir: /home/app/webapp ports: - "80:80" environment: - PASSENGER_APP_ENV=development volumes: - .:/home/app/webapp networks: - back-end db: container_name: db image: postgres:9.4 networks: - back-end networks: back-end: driver: bridge 

我不知道为什么会发生这种情况,而且我提出了一个问题 ,但同时,这是一个解决方法:

 docker-compose run webapp bundle exec rails db:migrate 

请用适当的解决方法回答这个问题,我会接受你的答案。