We extend a previously developed method for constructing shallow water models that conserve energy and potential enstrophy to the case of flow bounded by rigid walls. This allows the method to be applied to ocean models. Our procedure splits the dynamics into a set of prognostic equations for variables (vorticity, divergence, and depth) chosen for their relation to the Casimir invariants of mass, circulation and potential enstrophy, and a set of diagnostic equations for variables that are the functional derivatives of the Hamiltonian with respect to the chosen prognostic variables. The form of the energy determines the form of the diagnostic equations. Our emphasis on conservation laws produces a novel form of the boundary conditions, but numerical test cases demonstrate the accuracy of our model and its extreme robustness, even in the case of vanishing viscosity.