Why do I have to stop my containers in order to run them?

Viewed 14

I am developing a Ruby application in docker-compose, and I am trying to run browser-based tests. I have two docker-compose files. (there is a lot of duplication you can probably ignore)

docker-compose.yml

version: "3.9"
services:
  web:
    build: web
    container_name: web
    hostname: web
    command: bash -c "bundle exec rerun \"rackup --host 0.0.0.0 -p 3000\""
    volumes:
      - .:/web
      - gems:/usr/local/bundle/
    ports:
      - "3000:3000"
    tty: true
    stdin_open: true
  events:
    build: events
    container_name: events
    hostname: events
    command: bash -c "bundle exec rerun ruby events/server.rb"
    volumes:
      - .:/events
      - gems:/usr/local/bundle/
    ports:
      - "4567:4567"
      - "4568:4568"
      - "4569:4569"
      - "4570:4570"
    tty: true
    stdin_open: true
    depends_on:
      - game
  game:
    build: lib
    container_name: game
    hostname: game
    command: bash -c "bundle exec rerun ruby lib/server.rb"
    volumes:
      - .:/game
      - gems:/usr/local/bundle/
    tty: true
    stdin_open: true
volumes:
  gems:

and spec-system/docker-compose.test.tml

version: "3.9"
services:
  test:
    image: ruby:3.0
    volumes:
      - .:/code
      - gems:/usr/local/bundle/
    working_dir: /code
    depends_on:
      - web
      - events
      - game
      - firefox
    command: bundle exec rspec spec-system
  firefox:
    image: selenium/standalone-firefox
    container_name: firefox
    ports:
      - "7900:7900"
      - "4444:4444"
    shm_size: "2gb"
    restart: unless-stopped

The idea is that I run the tests with the following command:

docker-compose -f docker-compose.yml -f spec-system/docker-compose.test.yml run --rm test

which runs

bundle exec rspec spec-system

in the container. My issue is the following. The first time I run the command, everything works. The second time I run it, I get a timeout after 60 seconds. To get the tests to run a second time, I have to stop the running containers.

docker-compose -f docker-compose.yml -f spec-system/docker-compose.test.yml stop

Is there a way to make it so I can just run the test container the same way I would run rspec outside the container?

Backtrace for the timeout

$ docker-compose -f docker-compose.yml -f spec-system/docker-compose.test.yml run --rm test
Creating tissue_test_run ... done
F

Failures:

  1) addition 2+2
     Failure/Error: visit '/'

     Net::ReadTimeout:
       Net::ReadTimeout with #<TCPSocket:(closed)>
     # /usr/local/bundle/gems/selenium-webdriver-4.4.0/lib/selenium/webdriver/remote/http/default.rb:118:in `response_for'
     # /usr/local/bundle/gems/selenium-webdriver-4.4.0/lib/selenium/webdriver/remote/http/default.rb:77:in `request'
     # /usr/local/bundle/gems/selenium-webdriver-4.4.0/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
     # /usr/local/bundle/gems/selenium-webdriver-4.4.0/lib/selenium/webdriver/remote/bridge.rb:625:in `execute'
     # /usr/local/bundle/gems/selenium-webdriver-4.4.0/lib/selenium/webdriver/remote/bridge.rb:52:in `create_session'
     # /usr/local/bundle/gems/selenium-webdriver-4.4.0/lib/selenium/webdriver/common/driver.rb:323:in `block in create_bridge'
     # /usr/local/bundle/gems/selenium-webdriver-4.4.0/lib/selenium/webdriver/common/driver.rb:321:in `create_bridge'
     # /usr/local/bundle/gems/selenium-webdriver-4.4.0/lib/selenium/webdriver/common/driver.rb:74:in `initialize'
     # /usr/local/bundle/gems/selenium-webdriver-4.4.0/lib/selenium/webdriver/remote/driver.rb:43:in `initialize'
     # /usr/local/bundle/gems/selenium-webdriver-4.4.0/lib/selenium/webdriver/common/driver.rb:57:in `new'
     # /usr/local/bundle/gems/selenium-webdriver-4.4.0/lib/selenium/webdriver/common/driver.rb:57:in `for'
     # /usr/local/bundle/gems/selenium-webdriver-4.4.0/lib/selenium/webdriver.rb:89:in `for'
     # /usr/local/bundle/gems/capybara-3.37.1/lib/capybara/selenium/driver.rb:83:in `browser'
     # /usr/local/bundle/gems/capybara-3.37.1/lib/capybara/selenium/driver.rb:104:in `visit'
     # /usr/local/bundle/gems/capybara-3.37.1/lib/capybara/session.rb:278:in `visit'
     # /usr/local/bundle/gems/capybara-3.37.1/lib/capybara/dsl.rb:52:in `call'
     # /usr/local/bundle/gems/capybara-3.37.1/lib/capybara/dsl.rb:52:in `visit'
     # ./spec-system/example_spec.rb:5:in `block (2 levels) in <top (required)>'

Finished in 1 minute 0.18 seconds (files took 0.39642 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec-system/example_spec.rb:4 # addition 2+2

ERROR: 1
0 Answers
Related