尝试在正在运行的docker compose容器上运行Rails迁移会引发以下错误:
$ docker-compose run webapp rails db:migrate
ERROR: Cannot start service webapp: invalid header field value "oci runtime error: container_linux.go:247: starting container process caused \"exec: \\"rails\\": executable file not found in $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
?Docker文件
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
最佳答案
我不知道为什么会这样,我已经提交了issue,但是与此同时,这是一种解决方法:
docker-compose run webapp bundle exec rails db:migrate
请通过适当的解决方法回答此问题,我们将接受您的回答。
关于ruby-on-rails - 在$ PATH中找不到docker可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41167349/