In Minecraft how do I stop my dog from dying to other people

In my Minecraft survival server I have a dog named Charles (with a name tag) and I love him very much, but the people on my server are very destructive and I am afraid that when I leave they will kill him. Is there a way with commands to pervent my dog and only my dog from dying to them?


You can use /effect to give him resistance level 5. This will prevent him from all damage except void damage, starvations, and extremely strong explosions. (so this won't protect him if they bring in enough explosives).

For Java Edition:

/effect give @e[type=wolf,name=Charles] resistance seconds 5 

For Bedrock Edition:

/effect @e[type=wolf,name=Charles] resistance seconds 4

Replace seconds with the amount of time you want him to be invincible.