3

I was following this tutorial:

https://docs.docker.com/compose/rails/

I want to create a Ruby On Rails API with PostgreSQL Database (Dockerized)

But when I run

docker-compose run web rails new . --force --no-deps --api --database=postgresql

I got this:

Creating soft-vape-db ... done /usr/bin/entrypoint.sh: line 8: exec: @: not found

entrypoint.sh

#!/usr/bin/env bash
set -e
rm -f /myapp/tmp/pids/server.pid
exec "$@"

Dockerfile

FROM ruby:2.5
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
COPY . /myapp

COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000

CMD ["rails", "server", "-b", "0.0.0.0"]

docker-compose.yml

version: '3'
services:
  db:
    container_name: soft-vape-db
    image: postgres
    volumes:
      - ./tmp/db:/var/lib/postgresql/data
  web:
    container_name: soft-vape-api
    build: .
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    volumes:
      - .:/myapp
    ports:
      - "3000:3000"
    depends_on:
      - db

Any idea ?

Clement Montois
  • 184
  • 2
  • 12
  • 1
    I would just run `rails new` locally, and try to make your application work before you bring Docker into it at all. Package it in Docker as a _last_ step, not a first step. – David Maze Mar 13 '19 at 20:05
  • Try getting rid of the quotes. Use `exec $@`. – kichik Mar 13 '19 at 20:46
  • 1
    eh? How could your error state "error ... line 8" when your file have 4 lines? Are you sure the error is still relevant to the code you show here? – β.εηοιτ.βε Mar 13 '19 at 21:22
  • I just deleted the comments of the file ;) But it was for this line. – Clement Montois Mar 13 '19 at 22:35
  • I still have the error @kichik without the quotes :s /usr/bin/entrypoint.sh: line 8: exec: @: not found – Clement Montois Mar 13 '19 at 22:38
  • I'm having the same error - this may depend on your OS. On my mac the error is /usr/bin/entrypoint.sh: line 8: rails: not found. I know this means the ruby container we've pulled doesn't have gems on it yet. I'm not sure why. – Jason Michael Nov 12 '19 at 23:14

1 Answers1

2

The question is quite old but I also had this problem when using the example from docs so I hope this helps someone. The solution is pretty simple. The rails new command should be prepended with bundle exec.

So run docker-compose run web bundle exec rails new . --force --no-deps --api --database=postgresql

sonar0007
  • 86
  • 5