尝试在正在运行的docker compose容器上运行rails迁移会抛出此错误:
$ docker-compose run webapp rails db:migrate
错误:无法启动服务webapp:无效的头字段值" oci运行时错误:container_linux.go:247:启动容器进程导致\" exec:\\" rails \\&# 34;:在$ PATH \" \ n"
中找不到可执行文件
但是,我可以从容器内部访问rails:
$ 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
?
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
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
答案 0 :(得分:1)
我不知道为什么会这样,我已经提交issue,但与此同时,这是一个解决方法:
docker-compose run webapp bundle exec rails db:migrate
请妥善解决此问题,我接受您的回答。