The hollow mesoporous silica nanoparticles (HMSNs), which have been used as the nanocontainers for the corrosion inhibitor, benzotriazole, were fabricated using the hard-template method. Alkaline-responsive HMSNs based on cucurbituril (CB)/bisammonium supramolecular complex and acid-responsive HMSNs based on α-cyclodextrin (α-CD)/aniline supramolecular complex, which operate in water, have been achieved and characterized by solid-state NMR, thermogravimetry analysis, scanning electron microscopy, transmission electron microscopy and N2 adsorption-desorption analysis. The two elaborately designed nanocontainers show the pH-controlled encapsulation/release behaviors for benzotriazole molecules. Equal amounts of the alkaline- and acid-responsive nanocontainers were uniformly distributed in the hybrid zirconia-silica sol-gel coating and thus formed the intelligent anticorrosion coating. The self-healing property of AA2024 alloy coated with the intelligent anticorrosion coating is evaluated by electrochemical impedance spectroscopy (EIS). The sol-gel coating doped with the pH-responsive nanocontainers clearly demonstrates long-term corrosion protection performances when compared to the undoped sol-gel coating, which is attributed to the release of corrosion inhibitor from the nanocontainers after feeling the changes of environmental pH values near the corroded areas.