In many cases pre-packaged soil from the garden centre may serve its purpose when filling containers or raised beds. It is usually manufactured in massive amounts by mixing various raw ingredients before bagging. The packaging may make bold claims about the quality of its contents, but a gardener won't know with any certainty just what went into it.
The "purposes" of soil are many. For one, it holds the roots of plants in place and provides space to grow downward as the rest of the plant grows upward. Second, it feeds the plants through fertility by providing a range of nutrients and minerals to the growing plants. Soil also mitigates moisture - sometimes retaining it (as in seedling soil), and sometimes draining it quickly away (as in cactus mix). One could also discuss the role soil plays in providing an environment for microbial action, which in turn helps to strengthen plants.
In traditional garden thinking potting soil is made by combining peat, sand, and compost in various ratios. Peat is excellent at holding onto water, and sand for draining it away. Compost provides organic matter that feeds the soil biology. Some recipes incorporate perlite (an inert volcanic glass), or vermiculite (a type of mineral that is high in clay), to add loft to soil mixes, improving their drainage and providing pockets for oxygen.
Peat and perlite are both harvested from the environment, and are not renewable resources. Some gardeners prefer to use coir (coconut fibre) in place of peat since it is entirely renewable. We have recently seen the arrival of hemp-based products for seed starting, so there may be some potential to incorporate hemp fibres into soil mixes to replace both peat and coir.
Super Basic Container Soil Recipe
5 parts milled sphagnum peat or coir fibre
5 parts screened compost
3 parts coarse sand
2 parts perlite
1/2 part balanced organic fertilizer or homemade
If using peat, mix in an additional 1/4 part agricultural lime to stabilize the pH.
Try not to over-think this basic soil mix. Other ingredients can be added in as needed, depending on the intended purpose. For instance, the addition of extra sand and sharp grit would suit cacti and succulent plants, as well as alpine beds. Trees and large shrubs would benefit from the addition of bark mulch or even sawdust. For tomato plants it might be best to increase the peat to 6 parts in the recipe above. Many flowers perform better in soil that is less fertile, so cut back on the fertilizer if flowers are the intended end user.
There are a host of other potential amendments for soil mixes, but the container soil recipe above will work in most containers, and suit most garden plants.