-
Notifications
You must be signed in to change notification settings - Fork 18.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleanup docker tmp dir on start #31741
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🐸
daemon/daemon.go
Outdated
var tmpDir string | ||
if tmpDir = os.Getenv("DOCKER_TMPDIR"); tmpDir == "" { | ||
tmpDir = filepath.Join(rootDir, "tmp") | ||
os.RemoveAll(tmpDir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have the Docker for Mac team have a look as well; IIRC they store other data in this directory, and I don't know if that can be removed; IIRC, we use specific prefixes for partial pulls, and build contexts, so we could be more specific and just remove those directories
In addition, we recently merged a PR for scenarios where docker when running dind (see #31265); which also removed the content instead of the directory itself would that make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌 for waiting on D4M (ping @justincormack ?) to have a look. Although, it's a temp directory, nothing is there should be assumed to survive be valid after a restart ;-)
Regarding the second point, I'm not sure I understand. If you remove the directory, you also remove its content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
second point is for a case where you'd bind mount /var/run/docker/tmp
in that case, removing the directory itself would fail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, I see I typed an also
sorry, I see the confusion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thaJeztah I only delete if the path is /var/lib/docker/tmp
though. If the user specified a different path, I let it be.
I'm not sure how large the tmpdir would be 😅 , but if it can be large, we could call |
@AkihiroSuda mine was 2/3 GB, I'll update the PR with your suggestion :) |
f7f47e2
to
84bb85d
Compare
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
84bb85d
to
9c451ad
Compare
ping @thaJeztah @AkihiroSuda 👼 |
var tmpDir string | ||
if tmpDir = os.Getenv("DOCKER_TMPDIR"); tmpDir == "" { | ||
tmpDir = filepath.Join(rootDir, "tmp") | ||
newName := tmpDir + "-old" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a daemon crashes before completely removing tmpDir + "-old"
, the next daemon execution fails to execute os.Rename(tmpDir, tmpDir+"-old")
, and hence the old tmpDir + "-old"
will be left alone.
So I think we need os.RemoveAll(tmpDir + "-old")
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and what if that one fails? ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
(backport from moby#31741) Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com> Signed-off-by: Wentao Zhang <zhangwentao234@huawei.com> (cherry-pick from 9c451ad) Conflicts: daemon/daemon.go
Signed-off-by: Kenfe-Mickael Laventure mickael.laventure@gmail.com
--
This should free up some space by removing old build contexts.