The ecology of microbes in the gut has been shown to play important roles in the health of the host. To better understand microbial growth and population dynamics in the proximal colon, the primary region of bacterial growth in the gut, we built and applied a fluidic channel that we call the "minigut." This is a channel with an array of membrane valves along its length, which allows mimicking active contractions of the colonic wall. Repeated contraction is shown to be crucial in maintaining a steady-state bacterial population in the device despite strong flow along the channel that would otherwise cause bacterial washout. Depending on the flow rate and the frequency of contractions, the bacterial density profile exhibits varying spatial dependencies. For a synthetic cross-feeding community, the species abundance ratio is also strongly affected by mixing and flow along the length of the device. Complex mixing dynamics due to contractions is described well by an effective diffusion term. Bacterial dynamics is captured by a simple reaction-diffusion model without adjustable parameters. Our results suggest that flow and mixing play a major role in shaping the microbiota of the colon.