5

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.

3
  • 1
    It is checking your Disk space, not your RAM. Commented Mar 5, 2019 at 14:34
  • Thank you! I got the problem fixed by deleting some files from my disk. Commented Mar 5, 2019 at 14:38
  • 3
    In my case, even if I had removed files from the disk, only that worked was this command: docker stop $(docker ps -a -q);docker kill $(docker ps -q);docker rm $(docker ps -a -q);docker rmi $(docker images -q) Commented Aug 5, 2019 at 15:02

2 Answers 2

5

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

Sign up to request clarification or add additional context in comments.

Comments

3

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

Update 2025 ========================

Following instructions from this site https://depot.dev/blog/docker-clear-cache

Sometimes the issue is dangling layers occupying space

To get rid of them, run docker system prune -a

Other times the problem may be volumes.

To prune local volumes, run docker volume prune -f

To run a more accurate diagnosis, run docker system df :


docker system df
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          138       34        36.18GB   34.15GB (94%)
Containers      74        18        834.8kB   834.6kB (99%)
Local Volumes   118       6         15.31GB   15.14GB (98%)
Build Cache     245       0         1.13GB    1.13GB

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.