Initiate the lock on Swarm cluster in Docker
Enable the lock on Swarm cluster in Docker
--Enable the autolock while creating the swarm cluster
#docker swarm init --autolock
--Enable the autolock with already exists swarm cluster
#docker swarm update --autolock=true
sunny@Oracle1:~/Desktop$ docker swarm update --autolock=true
Swarm updated.
To unlock a swarm manager after it restarts, run the `docker swarm unlock`
command and provide the following key:
SWMKEY-1-fYYS/AVW5WrhGC6POtrarbNpecqOHsMgAtZnYvJ+s4k
Please remember to store this key in a password manager, since without it you
will not be able to restart the manager.
sunny@Oracle1:~/Desktop$
Note: you need to remember the key for unlock and need to restart the service of docker for implement lock or unlock.
sudo systemctl restart docker
If you try to check the swarn node list then you will get the error without unlocking it as:
root@Oracle1:/home/sunny/Desktop# docker node ls
Error response from daemon: Swarm is encrypted and needs to be unlocked before it can be used. Please use "docker swarm unlock" to unlock it.
#docker swarm unlock -- Enter the key as generated above while setup the lock
root@Oracle1:/home/sunny/Desktop# docker swarm unlock
Please enter unlock key:
root@Oracle1:/home/sunny/Desktop#
root@Oracle1:/home/sunny/Desktop# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
qz7ctlqi486ogcmfchj8gphsb * Oracle1 Ready Active Leader 20.10.22
root@Oracle1
Disable the autolock in swarm cluster:
root@Oracle1:/home/sunny/Desktop# docker swarm update --autolock=false
Swarm updated.