Rigging problem with IK: why do the bones turn around? it's my first time doing this and I have no idea what to do. I have seen a lot of youtube tutorials and at some point my results differ from the video even if I followed it exactly. 
As you can see in the picture I cannot animate this rig properly. The leg bone will rotate around when going past the pole bone. Also the control bone doesn't stick to the joint, but moves freely. The control bones were cleared from the parent and deform deactivated. The yellow bones have a chain length of 2, everything else is default.

Thanks for your help
The floating bone controls which direction your knee bends. (or which direction you want your leg to direct). I assume you have 2 knee bone controllers instead of one controlling both. Play with the knee bones, I'm sure you will put 2 and 2 together real quick.