Learn Docker With My Newest Course

Dive into Docker takes you from "What is Docker?" to confidently applying Docker to your own projects. It's packed with best practices and examples. Start Learning Docker →

Docker Tip #71: Running Local and CI Tests for Your Applications

docker-tips-and-tricks.jpg

Running tests locally or inside a continuous integration server share the same workflow. This is one reason why Docker is so useful.

Quick Jump:
When it comes to developing your application, a typical workflow would be:
  1. docker-compose up to bring everything up
  2. Start hacking away on your code
  3. docker-compose exec web test to run your tests in a web service

That exec command will run your tests inside of the existing web service. This avoids the overhead of having to spin up an extra web container just to run your tests.

Depending on what code editor you use, you might even set things up so that when you press a key, it runs a variant of that exec command to limit tests for the specific file you’re working on, or even a specific function based on where your cursor is.

When it comes time to testing your app in CI, a typical workflow would be:
  1. docker-compose up -d to bring everything up in the background
  2. docker-compose exec web test to run your tests in a web service

Nothing changed other than we didn’t edit any code in between. From this point, you could do whatever you need to do when your tests pass, such as building production ready Docker images and pushing them to a Docker registry.

Free Intro to Docker Email Course

Over 5 days you'll get 1 email per day that includes video and text from the premium Dive Into Docker course. By the end of the 5 days you'll have hands on experience using Docker to serve a website.



Comments