In the case you have FSL installed, you can use
fslstats to compute that for you.
The usage syntax would be:
$ fslstats input.nii.gz -V
Note the capital V. This will output two numbers, the first is the number of voxels greater than 0, the second is their volume in cubic millimiters. Ex:
$fslstats $FSLDIR/data/standard/LowerCingulum_1mm.nii.gz -V
You can check the pixel dimensions of the file to see that the volume calculation is correct.