A knife is perfectly fine to make human attackers understand to better leave one alone, however a dog will not understand what "knife" means, nor what it does. having 1-2 plastic bags with dry dog or cat food in the pocket, which one can distribute when trying to get away, is the best strategy - because a) it does not involve any violence and b) stray dogs are corrupt and if you meet them more than once, they might still remember your mercy (they remember this for several years).
the only situation where violence against stray dogs is justified, is when they encircle one and prepare the attack. then one has to understand who the leader of the pack is, because when not neutralizing their leader, this will result in hospital - also in this situation dropping food yields higher chances of getting away without a scratch, than trying to kill one of them. unless grown up on a farm and knowing exactly how to do it, it might even be a delusion, that this might be an easy thing to do, because dogs aren't slow.
paying the duty is your best chance to trespass on their territory, when you have to (you're the intruder, not them). this just sometimes might lead to situations, where it can become difficult to get rid of them again, which is still better than violence - which they can only return with violence - and so violence should always be the very last resort, in pure self-defense. running a few times around the block and entering a few houses makes it impossible for them to track you down, even if they already knew where your apartment was.
they can smell your fear; that's exactly why dry food is a good approach. being seen (smelt) as provider for snacks is anytime better than being seen as possible prey. and if it really has to be a weapon, bolas should quite effectively body-stop a single dog... and one should consider rabies (that's why close-combat is an unpredictably dangerous situation). Concerning the suggesting to use pepper spray ...this works in both directions, which is merely depending in which direction the wind blows. do not turn your back on them and try to appear as large as possible. better save than sorry.
Clarification for people comparing stray domesticated dogs with wild bears:
I've found tons of relevant behavioral studies (in German & English): https://www.wolfscience.at/en/research-at-wsc/publications/ and generally, one just cannot claim that a bear would be "highly collaborative with humans", which wolves and dogs are. and this collaborative behavior is exactly why collaborating with them is a pretty sane approach - and this is not feeding wild animals. read closely, I've wrote "when trying to get away", which implies that feeding them should not be the default - but it can help to take shortcuts on the way, which one otherwise would rather avoid.
I mean, other answers suggesting smashing the dog's skull receive up-votes... while answers, which can be backed up with a little research, that merely suggest common sense are being down-voted? this tells an awful lot about this community. stray dogs are still domestic animals. that humans do not consider them as pets, only because they don't have a name, does not matter.
The comparison to postal services is fitting, because territorial invasion is a huge factor... I'd still punch the postman, if he'd spray my dog, only to deliver an invoice, which by itself barely is sane - and only proofs, that some people refuse to realize, that they are the invaders, because they do not realize the territory claimed, eg. by a pack of stray dogs. if they follow one once, one can see where the borderline is, because this is exactly where they will leave off. I find it interesting, that a "trust in authority" answer is the most popular on "The Great Outdoors". SO is rather welcoming.