One of the ways to collect them is to make them teleport off the bedrock they spawn on, dig the block underneath the block the egg is on top of, place a torch in that place and break the block underneath the egg; it will drop as an item. Another way to obtain the egg is placing a piston facing the dragon egg and then pushing the dragon egg. Be careful not to let the dragon egg fall into the portal. And as last you punch a block near the dragon egg and then slowly move to the dragon egg without releasing the mouse button. Punching with the hand is enough to break it.
A dragon egg can also be made using Alkahestry, Tome of Alkahest surrounded by diamond blocks in a crafting table.