Trying to run a rails migration on a running docker compose container throws this error:
$ 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"
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
How do I run rails db:migrate
in my container?
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 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