Running RSpec specs with docker and docker-compose

  docker, rspec, ruby-on-rails

I’m building a simple RoR application using Docker and docker-compose for faciliting my development setup.

The application is running with no problems with Docker/docker-compose but, when I’m trying to run RSpec spec with it, the Puma runs but specs not. See below:

# With Docker only:
$ docker container run simpleblogapp bundle exec rspec
    => Booting Puma
    => Rails 6.1.4.1 application starting in development 
    => Run `bin/rails server --help` for more startup options
    Puma starting in single mode...
    * Puma version: 5.5.0 (ruby 3.0.2-p107) ("Zawgyi")
    *  Min threads: 5
    *  Max threads: 5
    *  Environment: development
    *          PID: 7
    * Listening on http://0.0.0.0:3000
    Use Ctrl-C to stop

# With docker-compose
    $ docker-compose run -e "RAILS_ENV=test" simpleblogapp bundle exec rsepc
    Creating simple_blog_app_simpleblogapp_run ... done
    => Booting Puma
    => Rails 6.1.4.1 application starting in test 
    => Run `bin/rails server --help` for more startup options
    Puma starting in single mode...
    * Puma version: 5.5.0 (ruby 3.0.2-p107) ("Zawgyi")
    *  Min threads: 5
    *  Max threads: 5
    *  Environment: test
    *          PID: 7
    * Listening on http://0.0.0.0:3000
    Use Ctrl-C to stop

When I’m run the RSpec directly, without Docker/docker-compose, it’s works fine.

This is my Dockerfile and docker-compose.yml:

# Dockerfile
FROM ruby:3.0.2-alpine3.14

# install Ruby on Rails 6
RUN apk update 
  && apk add --update --no-cache 
    build-base 
    curl-dev 
    git 
    sqlite-dev 
    yaml-dev 
    zlib-dev 
    nodejs 
    yarn

WORKDIR /simple_blog_app
COPY Gemfile /simple_blog_app/Gemfile
COPY Gemfile.lock /tmp/Gemfile.lock
RUN gem install bundler --no-document
RUN bundle config --local disable_platform_warnings true
RUN bundle install --no-binstubs --jobs $(nproc)
COPY . /simple_blog_app

# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT [ "sh", "/usr/bin/entrypoint.sh" ]
EXPOSE 3000

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



# docker-compose.yml
version: '3.4'

services:
  simpleblogapp:
    image: simpleblogapp
    build:
      context: .
      dockerfile: ./Dockerfile
    ports:
      - 3000:3000

PS: I’m recently chance my SO to Ubuntu, where it was run normally, for Fedora Workstation 34.

Source: Docker Questions

LEAVE A COMMENT