-
Notifications
You must be signed in to change notification settings - Fork 77
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
Stop and Start Containers in Docker Swarm mode #2
Comments
Docker-Compose can handle generic container names and fixed names. For Example:
You can't simply move volumes from one stack to the other if the docker-compose stacks use different compose project names. The default project name is the docker-compose folder but you can set the project name yourself with environment variables on you computer:
Usually I migrate the volumes from one stack to the other:
|
Thanks for the quick feedback. Yep, that works with Docker-Compose... Doesn't with Docker Swarm. Apart for And in any case, when stopping a container, Swarm mode automatically starts another container, with a different hash at the end of container name. The only way to make sure that the volume is not tempered with during the backup would be to stop the service, which means removing it... which means that the service cannot be restarted without being redeployed. Am I correct? Does it mean that Volumerize cannot really be used as it is today in Swarm mode? Or does it mean that it needs to be associated with a tool that does hot backup such as the docker volume plugin from Blockbridge? |
Interesting topic. Actually you could say that any Docker integrated plugin will beat any self-constructed image solution. Volumerize is a Docker wrapper around the best cli solution i could find: Duplicity. Duplicity itself does not have any functionality for Docker purposes. You could say that Volumerize is the best multi-purpose and most importantly free solution to deal with the backup problem. Volumerize is a drop-in solution that can be used without installing and configuring anything. And even Blockbridge does not support as many storage backends as Duplicity. Well yes, Duplicity is in need of a Discovery mechanism otherwise it will not be able to track containers simply by their names. Example: Container-To-Backup
Afterwards Volumerize simply needs to be told which IDs to stop rather than looking for a specific container name. Well this would be work in progress. |
Interesting indeed... And I did not think about Gotta rush right now, but if volumerise could look for containers that would include the string |
Only applications which are read-only can be freezed and later on secured. Otherwise there is always the possibility to corrupt data when you freeze in the middle of write operations. Especially when you try it with a database. |
I think I got it. The reason the swarm was restarting the containers was that the Then, instead of passing container names to Volumerize, service names should be passed. Volumerize would then find all the containers related to the service; stop them; back them up; restart them. So the steps go on like this:
Should there be any pb in that sequence, an error should be logs and the process be set to fail. (QUESTION: does Volumerize currently do that with existing features, so that it can be minitored?_ The documentation should be as follows: Docker Service RestartsThis image can stop and start all containers in a Docker service before and after backup. Docker services are specified using the environment variable Note: the Example:
Note: Needs the parameter Example:
Test the routine!
|
Currently Volumerize can work with the following Docker
It obviously cannot work with the following policy:
The default is:
Docker-Compose V3 additionally offers the What I want to say is that Volumerize is not being able to be responsible for a specific restart policy of a specific technology. The user must understand that you cannot backup a container that restarts itself autonomously. And Volumerize, in its current state, cannot be responsible, when the user is not even aware if its container restart policies. Everybody using Volumerize should be aware of the basics of doing safe backups. I will redocument the restart section though. I really like the idea of using service names but this is also no term supported by Kubernetes or Cattle. Therefore I would like to go to apply a specific ID environment variable on the target container and process that one. All in all I think this calls for a swarm specific image of Volumerize that can work like that. Support Swarm features and terms. I would like to support this with extension points inside my scripts but I will not be able to implement and support this specific image by myself. I do not use Docker Swarm myself. Monitoring: Volumerize uses Jobber as a periodic task scheduler. You can check the logs for successfull runs and failures. Also you can check the tasks state with the |
Agree with what you say and your point is quite sound. Will have to think about how to bring that forward. I will close this issue for now, and further comment as needed. |
Actually, I found a solution, and it is so simple, I am asking whether it should not be considered to be added to this image. For the usage, the solution would be only to add a environment variable Currently the code is this: volumerize/imagescripts/create_docker_scripts.sh Lines 21 to 32 in f8ed523
and it would be changed to this: if [ -n "${VOLUMERIZE_CONTAINERS}" ]; then
DOCKER_CONTAINERS=${VOLUMERIZE_CONTAINERS}
for container in $DOCKER_CONTAINERS
do
if [ -n "${SWARM_MODE}" ] && [ "${SWARM_MODE}" = "true" ]; then
cat >> ${VOLUMERIZE_SCRIPT_DIR}/stopContainers <<_EOF_
docker ps --filter "name=${container}." --format "{{.Names}}" > ${VOLUMERIZE_SCRIPT_DIR}/${container}_containers_list; cat ${VOLUMERIZE_SCRIPT_DIR}/${container}_containers_list | xargs -n1 docker stop $line
_EOF_
cat >> ${VOLUMERIZE_SCRIPT_DIR}/startContainers <<_EOF_
cat ${VOLUMERIZE_SCRIPT_DIR}/${container}_containers_list | xargs -n1 docker start $line
_EOF_
else
cat >> ${VOLUMERIZE_SCRIPT_DIR}/stopContainers <<_EOF_
docker stop ${container}
_EOF_
cat >> ${VOLUMERIZE_SCRIPT_DIR}/startContainers <<_EOF_
docker start ${container}
_EOF_
fi
done
fi What do you say? EDIT: Need to see whether writing code with a |
I really thank you providing me with the discovery docker command! Have you tested it? |
Yes I have. Works a treat. |
I have tested the command in my environment. On the other side going through labels gives a more sound solution, e.g.
Is there also a way docker swarm defines label we can use? You can check with |
Sorry for the late reply. Yes, it behaves arbitrarily because Swarm will create containers to fulfil the service that has been created. The string will be of the format In the code I suggested, So the fact that the
provides indeed a cleaner solution! |
Is this merged? |
Hi,
This is more of a question than an issue. I used volumerize to backup some Docker Compose managed named container volumes and it works great. Now I have moved to Docker Swarm and I am running into problems.
One of them was that to get the right volume names, which I resolved by putting the volumerize container in the same stack.
The second pb I have, not resolved yet, is about stopping and starting containers. Since the container managed by Swarm have names that cannot be determined in advance, I cannot use the
VOLUMERIZE_CONTAINERS
variable.Any clue on how to work around this?
The text was updated successfully, but these errors were encountered: