Firstly, referring to guidance (as linked to in other answers) can certainly be useful but you need to be careful as guidance does not generally carry the weight of law and often uses paraphrasing which can lead to subtle inaccuracies. If you want to be sure it's always best to refer directly to the legislation.
Secondly, there is no such thing as a "UK" jurisdiction when it comes to law, so the exact answer depends on where you have arrived from abroad. The UK is made up of four jurisdictions: England, Wales, Northern Ireland, and Scotland. Any given law could apply to any combination of those.
The relevant law here for England is the Health Protection (Coronavirus, International Travel and Operator Liability) (England) Regulations 2021.
Regulation 9 provides that when you arrive in England from a so-called "amber" country (a "category 2" country in the regulations) you must usually self-isolate. Some people are exempt but I'll assume that is not applicable here.
Regulation 9(11) provides the list of exceptions to the requirement to self-isolate. I won't copy the entire list here (you can click the link above to see it), but suffice to say there is no specific exception for obtaining a 2nd dose of a vaccine. The following medical exception is available, but it's hard too see that a 2nd dose could be considered urgent or that you will be able to get a doctor's advice that you cannot wait until the self-isolation period has ended:
Regulation 9(11)(b): "to seek medical assistance, where this is required urgently or on the advice of a registered medical practitioner, including to access services from dentists, opticians, audiologists, chiropodists, chiropractors, osteopaths and other medical or health practitioners, including services relating to mental health"
There is also a catch-all "exceptional circumstances" provision at regulation 9(11)(i). This means that you can break your self-isolation for any reason (including one which isn't specifically mentioned) provided that it constitutes exceptional circumstances. Whether it does or not would be a matter for the courts to decide if it came to that. The regulation gives some (non-exhaustive) examples of what might constitute exceptional circumstances. One of them is:
"to obtain basic necessities such as food and medical supplies for those in the same household (including any pets or animals in the household) where it is not possible to obtain these provisions in any other manner"
The problem here is similar to the first exception: it is hard to imagine that a 2nd dose is exceptional circumstances or even basic "necessities" since there is no compelling reason you can't just wait a few extra days to get it.
As a side note, the above is a good example of where guidance can be inaccurate. From this answer you can see that the guidance says "get basic urgent necessities like food and medicines where you cannot arrange for these to be delivered", but as you can see the actual rule is wider than that - you need to be unable to obtain the necessity in any other manner, not just from a delivery.