I did /Summon in minecraft and I summoned an ender dragon. My friend and I thought it would be cool if we built a cage for the ender dragon. We build a huge cage out of end stone, obsidian and bedrock. We summoned the ender dragon in the cage, and it could fly right out of the cage. mobGriefing was off, and we used blocks that the ender dragon couldn't destroy. Is there any way we can keep him from flying out of a cage? The cage was definitely big enough for at least 3 ender dragons.
As FEichinger explained, it's impossible keep an Ender Dragon in place using building blocks.
Use a clock to repeatedly execute the command:
/tp @e[type=EnderDragon] X Y Z
And the Ender Dragon will be stuck in that location, but will shake quite a bit because it will try to move constantly...
Of course, you can add a cage around the Dragon as a cosmetic feature...
This can easily be tested in a superflat world in creative mode. Spawning a dragon and luring it through the Bedrock leads to these results:
As the screenshot shows, the Bedrock layer remains intact desipte the Dragon's attempts - And the dragon flies through it without a problem.
Conclusion: It is not possible to keep an Ender Dragon trapped in one location.