CodeMasterLeader123
CodeMasterLeader123

Reputation: 41

java.lang.AssertionError: Docker environment has more than 2GB free

I have been creating tests for my program that uses docker. And everything was working well until suddently I face this problem at the start of any test

ℹ︎ Checking the system...
    ✔ Docker version is newer than 1.6.0
    ✘ Docker environment has more than 2GB free

Test ignored.

Test ignored.

java.lang.AssertionError: Docker environment has more than 2GB free

at org.rnorth.visibleassertions.VisibleAssertions.fail(VisibleAssertions.java:437)
at org.rnorth.visibleassertions.VisibleAssertions.assertTrue(VisibleAssertions.java:129)
at org.testcontainers.DockerClientFactory.checkDiskSpace(DockerClientFactory.java:168)
at org.testcontainers.DockerClientFactory.lambda$client$1(DockerClientFactory.java:127)
at org.testcontainers.DockerClientFactory.runInsideDocker(DockerClientFactory.java:230)
at org.testcontainers.DockerClientFactory.client(DockerClientFactory.java:118)
at org.testcontainers.containers.GenericContainer.<init>(GenericContainer.java:116)
at my.project.historyservice.MongoDBTest.<clinit>(MongoDBTest.java:24)
at sun.misc.Unsafe.ensureClassInitialized(Native Method)
at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:43)
at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:156)
at java.lang.reflect.Field.acquireFieldAccessor(Field.java:1088)
at java.lang.reflect.Field.getFieldAccessor(Field.java:1069)
at java.lang.reflect.Field.get(Field.java:393)
at org.junit.runners.model.FrameworkField.get(FrameworkField.java:73)
at org.junit.runners.model.TestClass.getAnnotatedFieldValues(TestClass.java:230)
at org.junit.runners.ParentRunner.classRules(ParentRunner.java:255)
at org.junit.runners.ParentRunner.withClassRules(ParentRunner.java:244)
at org.junit.runners.ParentRunner.classBlock(ParentRunner.java:194)
at org.junit.runners.ParentRunner.run(ParentRunner.java:362)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

The class MongoDBTest starts with:

public class MongoDBTest
{
  @ClassRule
  public static GenericContainer mongodb = new GenericContainer("mongo:3.6")
          .withExposedPorts(27017)
          .waitingFor(Wait.forListeningPort());

With line 24 being the one where I call "new GenericContainer"

I cant figure out what can be the problem. My computer has 16GB of RAM, out of which about 10GB should be free. I ran the test about 10 times successfully today before the problem arose, and I have tried restarting computer but it didnt help.

Upvotes: 4

Views: 6567

Answers (2)

Mart&#237;n Zaragoza
Mart&#237;n Zaragoza

Reputation: 1817

Sometimes volume data is the culprit (at least it was for me).

Removing unused volumes and dangling images data can free up a lot of space.

Try running docker system prune --volumes

This command removes:

  • all stopped containers
  • all networks not used by at least one container
  • all volumes not used by at least one container
  • all dangling images
  • all dangling build cache

In my case it freed up close to 32GB of disk space

Hope this helps

Upvotes: 3

Ansel Zandegran
Ansel Zandegran

Reputation: 656

docker rmi $(docker images -q) does the trick thanks to @pafede2

Upvotes: 5

Related Questions