When working with Docker containers on CircleCI, if you try to run docker run with the --rm flag your builds will fail with the error message below:
Error removing intermediate container 1f3a1d541241:
Driver btrfs failed to remove root filesystem
1f3a1d541241e757d48f34329508253e9ee139380b7b914a3b1104677eb0e8ee:
Failed to destroy btrfs snapshot: operation not permitted
Docker gives this error because it’s not possible to remove the container image in the file system that we are using on CircleCI. We are working to fix the Docker daemon so that it does not not try to remove intermediate container image to suppress the error in the future container release.
Workaround
In order to fix this issue for now, skip this step by removing the --rm flag from the docker run command.
We totally get that this is a pretty hacky workaround and is not ideal for most people. Another suggested workaround from this blog post comment is to return true after the rm commant. - docker rm -f CONTAINER_NAME || true with this method even though the container is not actually removed, the tests will continue to run. This also means that in environments that support removing the Docker container it will still be removed. This way you do not have to maintain two separate docker configurations.
That would be great to get this issue fixed so that docker run --rm works. I use --rm to clean up containers after they have been run locally on my development machine. It would be a shame to add special code for tests to pass on CircleCI.
Not sure if this can be fixed since the problem appears to be related to docker running in an unprivileged LXC container. CircleCI will likely never use privileged LXC containers for builds. This would need to be fixed upstream on the Docker/LXC side.
Does this mean heroku docker:release can’t work on CircleCI? I haven’t been able to deploy this way despite being told by one of your support engineers that this is possible, and the error I keep getting is related:
Error response from daemon: Driver btrfs failed to remove root filesystem 965c64a946e9456e7de152d44c839d189e4583108e1de95d25577e1d9ddeaa23: Failed to destroy btrfs snapshot /var/lib/docker/btrfs/subvolumes for 965c64a946e9456e7de152d44c839d189e4583108e1de95d25577e1d9ddeaa23: operation not permitted
Error: failed to remove containers: [965c64a946e9456e7de152d44c839d189e4583108e1de95d25577e1d9ddeaa23]
A Heroku employee has forked the heroku-docker plugin to make docker rm optional.
I’ve pushed a proof-of-concept showing how to use his fork. This isn’t optimized with caching, but if anyone would like to figure that out and share, that would be very welcome.
I’m hitting this even though I’m not using any volumes at all and I’m not using docker CLI (I’m directly hitting the remote API) so it’s even harder for me to workaround this.
Unfortunately, in our tests, docker-compose run does not return the correct exit code from the run command/script without the --rm flag (screenshot attached (tried with 1.6-1.7).
Has there been any progress on this. I’m seeing this same error while evaluating CircleCI and I’m unable to build a simple Java HelloWorld Spring Boot app and build a container.
Seemingly this is not high up on the priority list. Travis CI, however has worked flawlessly with Docker, allowing it to remove containers as and when required.
Thanks, I see the same thing when building an image as well. It is safe to ignore for most cases. If your image is failing to build it is very likely causes by some other issue.
Also seeing this when trying to build images. It’s causing errors in the built images.
Getting docker: Error response from daemon: rpc error: code = 2 desc = "oci runtime error: not a directory". from the docker daemon when trying to run the images.
Removing intermediate container would be to my understanding mandatory in builds where you want to smoke test your Docker images before pushing them into registry.
When I’m trying to run a container from the image I’ve built during build process I get error because the intermediate container is reserving the port that the smoke test container is also trying use.
I’m still running into this error when clearly the problem is not with the build script or the building, but with CircleCI. Exact same error, cannot remove intermediate containers.
Please see this previous response. This is a known issue and will likely never be fixed on our SaaS solution since it requires us to run unprivileged LXC containers.