在$ PATH中找不到docker可执行文件 [英] docker executable file not found in $PATH
问题描述
尝试在正在运行的docker compose容器上运行Rails迁移会引发以下错误:
Trying to run a rails migration on a running docker compose container throws this error:
$ docker-compose run webapp rails db:migrate
错误:无法启动服务webapp:无效的标头字段值 oci运行时错误:container_linux.go:247:导致启动容器进程\ exec:\\ rails\\:在$ PATH\ \n中找不到可执行文件
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"
但是,我可以从容器内部访问滑轨:
However, I can access rails from inside the container:
$ docker-compose run webapp bash
root@3fd3a87275a1:/home/app/webapp# which rails
/usr/local/rvm/gems/ruby-2.3.1/bin/rails
我的容器已经在运行,我可以获取页面:
My container is already running and I can GET the page:
$ 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
我如何在容器中运行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
Docker Compose
Docker Compose
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
推荐答案
我不知道为什么会这样,并且我已经提交了问题,但与此同时,这是一种解决方法:
I don't know why this is happening, and I've filed an issue, but in the meantime, here's a workaround:
docker-compose run webapp bundle exec rails db:migrate
请以适当的方式回答此问题,我会接受您的回答。
Please answer this question with a proper fix, and I'll accept your answer.
这篇关于在$ PATH中找不到docker可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!