Melons and pineapples have a long history of being grown in pots successfully under glass in the UK. Because they need a long, hot growing season to ripen properly, growing them in the greenhouse ...
but if growing in cooler climates, use a terracotta pot as this will help avoid cold, damp soil, which pineapples hate. When planting in the ground, create a ridge or raised bed for good drainage.