We discuss the thermodynamics of a general nonlinear electrodynamics (NLED) asymptotically flat black hole enclosed in a finite spherical cavity. A canonical ensemble is considered, which means that the temperature and the charge on the wall of the cavity are fixed. After the free energy is obtained by computing the Euclidean action, it shows that the first law of thermodynamics is satisfied at the locally stationary points of the free energy. Focusing on a Born-Infeld (BI) black hole in a cavity, the phase structure and transition in various regions of the parameter space are investigated. In the region where the BI electrodynamics has weak nonlinearities, Hawking-Pagelike and van der Waals-like phase transitions occur, and a tricritical point appears. In the region where the BI electrodynamics has strong enough nonlinearities, only Hawking-Page-like phase transitions occur. The phase diagram of the BI black hole in a cavity can have dissimilarity from that of a BI black hole using asymptotically anti-de Sitter boundary conditions. The dissimilarity may stem from a lack of an appropriate reference state with the same charge and temperature for the BI-AdS black hole.