This is still an issue, but this got it working, cheers!
Just a note to anybody else affected out there, this didn’t work on my first attempt and I think it’s because I don’t allow non-root to run docker, so the RAILS_ENV=test wasn’t getting passed through sudo.
So if you’re like me, use this to drop, create and migrate the db instead:
sudo d/shell
cd /src
RAILS_ENV=test rake db:drop db:create db:migrate