How to run docker commands in Scala?

Viewed 231

I try to write integration tests in scala. I have a docker files for the integration tests.

I want to run docker container before tests, and stop all of them after tests.

I have to use docker command like docker run ... to up docker containers.

How can i do that in scala with type safe? For example,

Docker.runCommand("docker run ...")
Docker.stopAll(containerids)

Etc

1 Answers

Unsure what testing framework you're using, but if you're using scalatest, you can use the trait BeforeAndAfterAll which runs a function before and after running the test suite.

for example....

class YourTestSuite extends FunSuite with BeforeAndAfterAll {

  override def beforeAll() {
    Docker.runCommand("docker run ...")
  }

  override def afterAll() {
    Docker.stopAll(containerids)
  }
}

Other testing frameworks will most likely have equivalent functionality

Related