It is best to think of friction as a force that tries to eliminate relative motion between objects. In most cases things slide on the ground, and therefore friction tends to prevent that slippage (or relative motion) by slowing the sliding object down until it eventually comes to rest.
Let us now take a look at the friction between an object and a moving surface such as the containers on the flat bed train car above. Clearly the train car can move. It can speed up, slow down or make a turn around a track - all of which constitute acceleration. If the containers are to go with the train car, they too must accelerate at a rate that matches that of the train car. If they don't, they slide off the car.
Consider a train car starting from rest and accelerating to the right. If the containers don't accelerate to the right at the same rate as the car, they will slip. It is therefore the job of friction to prevent this slippage and to accelerate the containers to the right. Thus the static friction force acting on the containers is toward the right. On a level track, the maximum friction force determines the maximum rate at which the train car can accelerate such that the containers don't slip relative to it. The forces on each container look like this:
The friction on the containers always acts in the direction of the acceleration of the train car. If it didn't, the car would accelerate rightward and the containers leftward... and that wouldn't end well. Regardless of the direction of the acceleration of the train car - since it changes if the car speeds up versus slows down versus turns - the friction on the containers will act in that direction. The biggest magnitude of acceleration that friction can cause on the container is just