How do I create a container entity that contains variable number of fields
I'm not sure if I understand correctly what you want to achieve, but the following two modules come to my mind that could be helpful:


Field collection 



  Field collection provides a field-collection field, to which any number of fields can be attached.



Field Group



  All fieldable entities will have the possibility to add groups to wrap their fields together. Fieldgroup comes with default HTML wrappers like vertical tabs, horizontal tabs, accordions, fieldsets or div wrappers. 


I suppose in your case Field Group would actually be the more interesting module to look at. You can wrap a group of fields and you can then set the number of the field group to unlimited.

You can also have groups inside of groups. But things can actually get a bit 'messy' when editing a node with grouped groups.