No, in these days of a fully volunteer defence forces (in the OECD anyway), they know that an 'employee' who doesnt want to be there, is worse than having having to trainup a raw recruit. So useally they won't stop someone leaving.
Here in Australia, there are 30 people applying for every enlistment spot, so its no big deal replacing someone.
In some situations though, one has to buy there discharge - I know someone who bought his discharge out of the navy after 4 months, because he couldn't 'get with the program' or just didn't want to.
Pilots in particullar have to pay many thousands to get an early discharge - In Australia, say you joined up as a trainee pilot, well you then have to sign an agreement saying that once the 6 years (or whatever it is) of training is up you then have to stay in the airforce for another 10 years (or something), as its not worth there while training you up otherwise. Its the same if you enlist as an aprentice, You have to agree to stay in the army, navy or airforce for so many years after your aprentiship is over, if you leave before that indentured period you have to buy your discharge.(the Australian defence forces have both civiilian aprentices & enlisted aprentices, they often work side by side, & even go to the same tech, one day a week. However when the civilian aprentice does his 4 years he gets nice big award tradesmen wages but no guarantee of future employment so he might have to look elseware for those tradesman wages, while when the enlisted aprentices does his 4 years he becomes a technician with the rank of warrent officer. When he finally does leave the services he'l also get a nice big trademens award wage as he'l have the same trade ticket as the civie bloke he did his aprentiship with).
Really its only in wartime or if you've been stockaded that 'quitting' is consided dessertion, these days.