There is a relatively rare condition where the sphincter at the end of the bile duct doesn't work properlyknown as Sphincter of Oddi Dysfunction. It may clamp shut and block the bile duct completely which will cause pain, distended ducts (when there is no gallbladder), liver function tests off the chart (even if there is nothing actually wrong with the liver), and ultimately jaundice.
Because the duct is shared with the pancreas you may also get pancreatitis which can be very serious. You should certainly go the the emergency room if you have any signs of yellowing (skin or eyes) or a high fever associated with the pain (possible pancreatitis), otherwise your choice whether you can deal with the pain.
You may also get diarrhoea when this happens as you won't be able to digest fat properly. I don't know of any clearcut recommendations for a diet that will help reduce the attacks. It is worth trying to lower your fat intake, eat regular meals, and eat more often and less at each meal. Known triggers for attacks are stress, stimulants like caffeine, some drugs including morphine and vitamins, alcohol, and vigorous exercise.
You may be able to try certain drugs to control the muscle behaviour but very often the solution is a minor surgery. The specialist will determine just what the best approach is in your case. It can be difficult to get a full cure of this condition and you may have to permanently adjust your diet after treatment.