(abridged) The present work is a first step to collect homogeneous abundances and near-infrared (NIR) luminosities for a sample of dwarf irregular (dIrr) galaxies, located in nearby groups. The use of NIR luminosities is intended to provide a better proxy to mass than the blue luminosities commonly used in the literature; in addition, selecting group members reduces the impact of uncertain distances. Accurate abundances are derived to assess the galaxy metallicity. Optical spectra are collected for Hii regions in the dIrrs, allowing the determination of oxygen abundances by means of the temperature-sensitive method. For each dIrr galaxy H-band imaging is performed and the total magnitudes are measured via surface photometry. This high-quality database allows us to build a well-defined luminosity-metallicity relation in the range -13 >= M(H) >= -20. The scatter around its linear fit is reduced to 0.11 dex, the lowest of all relations currently available. There might exist a difference between the relation for dIrrs and the relation for giant galaxies, although a firm conclusion should await direct abundance determinations for a significant sample of massive galaxies. This new dataset provides an improved luminosity-metallicity relation, based on a standard NIR band, for dwarf star-forming galaxies. The relation can now be compared with some confidence to the predictions of models of galaxy evolution. Exciting follow-ups of this work are (a) exploring groups with higher densities, (b) exploring nearby galaxy clusters to probe environmental effects on the luminosity-metallicity relation, and (c) deriving direct oxygen abundances in the central regions of star-forming giant galaxies, to settle the question of a possible dichotomy between the chemical evolution of dwarfs and that of massive galaxies.