During recharging, battery releases hydrogen and oxygen gases. It is known that hydrogen is a flammable gas, while oxygen is a substance that helps the combustion process. So the combination of those gasses could be flammable. Mixture of hydrogen and oxygen in a certain concentration when contact with fire or high temperature though only in one small spot, it could be exploded. More details about recharging battery can be read on: Charging Your Vehicle Battery.
In the dry cell battery, hydrogen and oxygen gases do not easily go out, and accumulated inside battery housing. If the battery is recharged too high and exceed the normal limits (overcharge), then production of hydrogen and oxygen are also much higher. So at some point will exceed the ability of the battery container and ultimately rupture the container aka battery to explode. Sealed battery such as dry battery (gel cell, Adsorbed Glass Mat, etc.) have higher risk of explosion then wet lead-acid battery.
Likewise, if too much battery load. When the current is going out of the battery, the battery also produces heat. If the heat is too high, then the amount of steam formed by heat is too much and the pressure will be too high and breaks battery container.
So, since the battery produces gases when recharge and discharge, then do not place it in a closed container.
Today dry cell batteries are popularly used. This type of battery has a maximum recharging voltage slightly lower than wet battery.
For example, for MK brand dry cell battery, the specification states that the charger voltage should be between 13.8-14.1 volts at a temperature of 20 degrees Celsius or 68 degrees Fahrenheit. Charger voltage must be reduced if temperature gets higher, in order to reduce gas formation. While some vehicles have a charging system with a voltage of 14.3-14.4 volts, so it can cause overcharge. At ambient temperature 30 degrees Celsius or 86 degrees Fahrenheit as in the tropics, maximum recharge voltage will drop to 13.5-13.8 volts. Therefore in cooler region like the subtropics, vehicle battery exploded by overcharge has less risk.
Few years a go, charging system voltage could be set as it was using electromagnetic switch (cut-off). Today the voltage regulation is done by Integrated Circuit (IC) and no longer adjustable. But lately there some are IC voltage regulators that can be adjusted. Apparently this adjustable IC voltage regulators are manufactured to suit a variety of different voltage to recharge batteries.
If you are using dry cell battery, the easiest way to prevent overcharge is to use a voltmeter to monitor battery voltage while driving. But now the voltmeter is not popular anymore as standard equipment on the dashboard, because IC voltage regulator is very stable. It is necessary to add a voltmeter to monitor battery voltage, if the voltage exceeds the maximum battery voltage, eg 14 volts, then immediately turn on the additional load such as lights, a/c, radio, tape, etc.. Reduce the engine revolution (RPM) by shifting to higher gear, or reduce speed.
Usually overcharge occurs when driving in the daytime with high engine revolution. High environment temperature will rise gas formation and lower gassing voltage. In some countries where it is compulsory to use headlight in the daytime, overcharge risk is lower as slightly lower alternator voltage due to current absorbed by headlight.
Now there are commercially available digital voltmeters that can be plugged into cigar lighter connector. As shown in below photo.
Circuit to monitor the battery voltage can be read in the article "Simple Battery Voltage Indicator With LED".
Shown below is a cut-off voltage regulator of an old alternator, voltage of this type regulator can be easily adjusted. The top cover is removed to show two electromagnet relays. But the regulated voltage is unstable.
Another way to prevent the battery explode by overcharge is to reduce the alternator output voltage, by placing diode in series between the alternator and battery. Diode reduces the voltage of 0.6 volts. So if your charging system voltage is 14.4 volts, then after installing diode voltage will drop to 13.8 volts. It should be ensured that the diode is capable to allow current strong enough to recharge the batteries and simultaneously turn on vehicle electrical systems such as: lights, a/c, ignition, fuel injection, engine management system, Electronic Control Unit (ECU), radio / tape, etc.. Minimum value of the current goes pass through the diode is about 50% of battery capacity, eg. for the 40AH battery, the resulting alternator current through the diode is 20 amperes. And of course the amount of current depends also to the amount of power (watts) of vehicle accessories.
Big sized diode is usually expensive and rarely sold. But it can be assembled from several small sized 2 amperes diodes. To make a big 20 A diode, it is required 10 pieces of parallel 2 A diodes. Photo below shows a parallel circuit of 2 A diodes. Alternator diode can do also.
Diagram for diode connection can be seen in the image below. Diode is connected between the alternator and battery, with the diode current flow from alternator to the battery. Supply power to the vehicle electrical system is connected to the positive pole of the battery, to ensure electric current can flow directly from the battery to the electrical system, without going through diode. The diode doesn’t allow electric current in the opposite direction.
Photo below shows the charging wire is pointed by red arrow. The cable is always the biggest of all alternator cables.
Be careful when connecting the wire from alternator to diode and to battery. Wire with large current must be well connected. Poor connection can increase resistance and generate heat, so it can end up with fire. Diode also requires cooling, place diode away from heat sources such as exhaust and radiator.