May vary from food bank to food bank, but they get donations in numbers of ways, which could include (in no particular order).
People donating food directly to the foodbank
People leaving food donations in drop of points in supermarkets (and elsewhere)
People making cash donations to the foodbank
Grants or funding that they can apply for
Collections done in places such as schools, churches etc, especially at times such as harvest (eg at harvest schools may ask for a food item in exchange for a non uniform day).
If they get donations, grants or other funding they use that to buy, often in bulk the items they need the most. People donating items may not know what is needed the most, so they could end up with lots of certain products, and not enough of others.
The food given out is in date - food banks usually request items will a long date stamp on, and often date the top of the tin/carton before putting it on the shelf so things are given out in date order.
Some food banks also offer fresh items, but it will depend on how that food bank works and where it gets its supplies from.
Still a support to people, but in a different way, some work more like a community pantry where people can pick a certain number of items from different types of products - sometimes paid for at a reduced rate other times free.
There are some organisations that use things that may otherwise be disposed of by supermarkets, but sometimes they cook meals with things that they are sure can still be used.
The foodbank I support is organised by those from a local church. Some of the volunteers are also from the church, others from the local community. The food bank is given food donations, and cash donations. They order food items that are needed -from the cash donations/funding. Knowing the people involved means I can ask exactly what they need most before purchasing.
Another foodbank I know of has a few drop off points local areas (a few houses, and a church in one village a few miles away from the foodbank). They collect each week from those drop off points. They also have a shop and sell second hand furniture, both so it is more affordable to people, and to raise funds.
There is no one way that food banks get the food - it all varies.