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

Add Running filter when stopping containers attached to a volume and rename functions for better clarity #93

Merged
merged 3 commits into from
Nov 7, 2022

Conversation

SscSPs
Copy link
Contributor

@SscSPs SscSPs commented Oct 11, 2022

closes #91

Signed-off-by: Sahil Soni SscSPs@gmail.com

…rename functions for better clarity

Signed-off-by: Sahil Soni <SscSPs@gmail.com>
Copy link
Collaborator

@felipecruz91 felipecruz91 left a comment

Choose a reason for hiding this comment

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

LGTM!

I've tested it by exporting a volume that is shared across 2 containers:

# 1. Launch a container that is running forever
docker run -d --name ctr-1 -v my-vol:/tmp alpine sleep infinity.

# 2. Launch a container that is stopped immediately after.
docker run -d --name ctr-2 -v my-vol:/tmp alpine /bin/sh

# 3. From the extension, export the volume "my-vol".

# 4. Only container "ctr-1" was stopped before exporting, then started again once the operation was completed. The container "ctr-2" remained stopped as it was originally.

Copy link
Member

@benja-M-1 benja-M-1 left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution @SscSPs! I think this PR solves the specific problem of the issue. However, I am wondering if the issue also exists with other container statuses. If so, it could be fixed in another PR.

var stoppedContainersByExtension []string
var timeout = 10 * time.Second

containerNames := GetContainersForVolume(ctx, cli, volumeName)
containerNames := GetContainersForVolume(ctx, cli, volumeName, filters.NewArgs(filters.Arg("status", "running")))
Copy link
Member

Choose a reason for hiding this comment

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

nit: From the list of status, I wonder if we should also filter "restarting" containers. When restarting, and during the backup process, they could also alter the data.
And could "removing" containers also add or remove data from an attached volume?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I had the same thought, there's a paused state as well, i am not sure how's the behaviour of the state transitions are, i can add these 3 as well in the filters,

Possible status: created, restarting, running, removing, paused, exited, or dead

I think we can take into consideration these 4: restarting, running, removing, paused.
In case of restarting, we can start it just fine,
And in case of removing, we can wait it's removal?
For paused,I'm not sure how we should handle it, although since it's paused, there shouldn't be a risk of data corruption, so we can probably ignore it.

Copy link
Member

Choose a reason for hiding this comment

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

In case of restarting, we can start it just fine.

I don't know if it is possible that a restarting container can write data into the volume. I guess yes, it could generate some logs that could be written into the volume.
So, when the backup is done, yes I agree, starting it seams fine.
However, if there is a container that is restarting when starting the backup, it could add data to the attached volume. So the container must be stopped.

And in case of removing, we can wait it's removal?

Looks like a good idea.

For paused,I'm not sure how we should handle it, although since it's paused, there shouldn't be a risk of data corruption, so we can probably ignore it.

I agree

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so I added changes to support restarting and removing statuses,
for restarting, we just treat it as running, stop it before cloning, and start it after cloning completes.
for removing, wait for removal to complete before we finish the StopRunningContainersAttachedToVolume function

Signed-off-by: Sahil Soni <SscSPs@gmail.com>
@felipecruz91 felipecruz91 merged commit 8b3a8fb into docker:main Nov 7, 2022
@AlbaRoza
Copy link

AlbaRoza commented Nov 8, 2022

Hi @SscSPs and thank you for stellar your contribution! In order to send you some Hacktoberfest-related swag, could you please send me an email to alba.roza@docker.com with your postal address and your t-shirt size? Thank you so much!

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.

Don't start stopped containers when cloning a volume
4 participants