Skip to content
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

Merged
merged 1 commit into from
Mar 30, 2017
Merged

Conversation

mlaventure
Copy link
Contributor

Signed-off-by: Kenfe-Mickael Laventure mickael.laventure@gmail.com

--

This should free up some space by removing old build contexts.

Copy link
Member

@vdemeester vdemeester left a 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)
Copy link
Member

@thaJeztah thaJeztah Mar 10, 2017

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?

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

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

Copy link
Contributor Author

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.

@AkihiroSuda
Copy link
Member

I'm not sure how large the tmpdir would be 😅 , but if it can be large, we could call rename(2) first and then remove it in background for better performance.

@mlaventure
Copy link
Contributor Author

@AkihiroSuda mine was 2/3 GB, I'll update the PR with your suggestion :)

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
@vdemeester
Copy link
Member

ping @thaJeztah @AkihiroSuda 👼

var tmpDir string
if tmpDir = os.Getenv("DOCKER_TMPDIR"); tmpDir == "" {
tmpDir = filepath.Join(rootDir, "tmp")
newName := tmpDir + "-old"
Copy link
Member

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.

Copy link
Contributor Author

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? ;-)

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thaJeztah thaJeztah merged commit f16d1a4 into moby:master Mar 30, 2017
@GordonTheTurtle GordonTheTurtle added this to the 17.05.0 milestone Mar 30, 2017
@mlaventure mlaventure deleted the cleanup-tmp-on-start branch March 30, 2017 18:32
liusdu pushed a commit to liusdu/moby that referenced this pull request Oct 30, 2017
(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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants