首页 > 解决方案 > 将参数附加到 docker compose test service 命令

问题描述

我试图找出一种方法来制作一个服务,该服务采用可选参数附加到服务(或条目)命令。例如:

  testing:
    <<: *backend
    environment:
      # Use the system rails environment or default to test
      - RAILS_ENV=${RAILS_ENV:-test}
    command: bash -c "bundle exec rspec"
    ports:
      - '3000:3000'

因此,如果我运行docker-compose run testing它将测试我的所有规范(这很有效),但我也可以附加参数来指定文件和/或行号,例如docker-compose run testing /specs/models/something.rb:33

编辑:我的目标是减少本地测试所需的打字量。目前将采取以下方式来指定特定的测试:

docker-compose run testing bundle exec rspec spec/models/something.rb:133

标签: ruby-on-railsdockerdocker-compose

解决方案


答案是entrypoint。设置服务,例如:

testing:
<<: *backend
environment:
  # Use the system rails environment or default to testing
  - RAILS_ENV=${RAILS_ENV:-test}
entrypoint: ["bundle", "exec", "rspec"]
ports:
  - '3000:3000'

然后运行特定的测试docker-compose run testing spec/models/something.rb:139


推荐阅读