Doing TDD with Docker

Today I watched the Weekly Iteration about Docker and after some trouble I’ve now gotten it working with my development environment.

I would like to do TDD with the app running in Docker, but it takes something like 10 seconds for docker-compose to start running the tests.

Here is an example of the command I run:

$ time docker-compose run web bin/rspec spec/models/user_spec.rb

Randomized with seed 15486
..........................................................

Finished in 2.92 seconds (files took 0.49527 seconds to load)
58 examples, 0 failures

Randomized with seed 15486

docker-compose run web bin/rspec spec/models/user_spec.rb  0.49s user 0.05s system 4% cpu 12.038 total

12 seconds seem kinda long to run just 58 specs.

Does anyone have experience with this?

@jferris

Hi @davidpdrsn, I’ve not done TDD with docker so @jferris can likely provide a more specific answer, but do you know if your bin/rails binstub has spring activated? The ~10 seconds you are seeing as overhead is consistent with Rails startup time when not running under spring, so it might just be that rather than docker overhead. It’s possible you could fix this by springifying your binstubs.

Ah the issue might be related to spring. Running docker-compose run web bundle exec spring status says that spring isn’t running, however my binstubs have been spingified. Works fine and quickly when I run the specs outside docker.

Is it possible that after running the tests the container gets shutdown, thus closing sping?

I haven’t gotten Spring working with Docker yet, but my startup times are generally reasonable.

% time docker-compose run web rspec spec/models/user_spec.rb 

Randomized with seed 40335
......

Finished in 0.09888 seconds (files took 1.93 seconds to load)
6 examples, 0 failures

Randomized with seed 40335

docker-compose run web rspec spec/models/user_spec.rb  0.25s user 0.03s system 6% cpu 4.075 total

I think using Spring could potentially cut a few seconds out, but I haven’t had time to look into it yet.