  We examine the entropy of self-gravitating anisotropic matter confined to a
box in the context of generalrelativity. The configuration of self-gravitating
matter is spherically symmetric, but has anisotropic pressure of which angular
part is different from the radial part. We deduce the entropy from the relation
between the thermodynamical laws and the continuity equation. The variational
equation for this entropy is shown to reproduce the gravitational field
equation for the anisotropic matter. This result re-assures us the
correspondence between gravity and thermodynamics. We apply this method to
calculate the entropies of a few objects such as compact star and wormholes.
