Let's start with the basics... why is a "barrel" called that anyway? To answer that, we have to go to the early days of making barrels. Back in the 1300s and 1400s, metallurgy was not as advanced as it is today, and neither were machining techniques. It was too time consuming to try and drill a hole through a solid cylinder of iron or bronze. So they had to use one or two different techniques to make barrels.
The first inventors of gunpowder were the Chinese and they used bamboo plants as their barrels. Bamboo tree trunks have naturally cylindrical hollow tubes and were plentiful in China as well, so it was natural to use these for small hand-cannons. The main problem with bamboo is that it can't take a lot of pressure, so the early hand-cannons could not fire powerful charges. Another alternative was to wrap the bamboo tubes tightly with rope to strengthen them.
The next technique to be used was casting. One of the oldest types of casting is called Green sand molding. First, a model (called a "pattern") of the barrel tube is made using an easily machined material such as wax or clay. Then the pattern is placed in hollow box frames (called "flasks") with no top or bottom. A couple of cylinders (called the "runner" and riser") are also placed in the box, touching the pattern. Wet green sand is poured into the flask and packed tightly around the pattern, the runner and the riser. After this, the runner, riser and pattern are removed, leaving hollows in the sand. Molten metal is then poured through the hole left by the runner tube and flows into the cavity left behind by the pattern and climbs up the riser. The metal is left to cool and harden and then the sand mold is broken to reveal the hardened casting. In another type of casting called "investment casting" or "lost wax casting", the pattern is not removed, but when molten metal is poured into the runner tube, it melts the wax and pushes it out via the riser tube. Incidentally, the "lost wax" casting method traces its history to India, centuries before guns were invented. Ancient Indians used this technique to make metal figurines and intricate jewelry. The Chinese were the first to employ casting techniques to make metal gun barrels and Arabs and Europeans also used this technique later. Cannon and gun barrels of cast-iron, bronze and brass were made using this method. It must be noted that casting technology was not fully developed and one of the major problems was that air bubbles trapped within the molten metal would leave hollows and cracks in the final product. To compensate for this, early gun barrels were made with very thick walls.
The next technique originated in Europe in the first half of the 14th century. In this method, the smith first makes a cylindrical pattern out of wood or clay, which is of the diameter and length desired. Next, the smith forges a number of iron bars of almost rectangular cross section and the same length as the pattern. These bars are fitted around the pattern as closely as possible, so there are no gaps between them. The pattern is then pushed out from the center, leaving the bars holding each other in place in the form of a tube. Then the smith forges a number of iron rings or hoops, whose diameter is slightly smaller than the diameter of the tube. The smith then heats these rings until they are white hot, which causes them to expand and they can be easily slipped around the iron bars. The rings cool and then contract, holding the metal bars in place.
For smaller pieces, instead of using bars of iron, the smith takes a flat rectangular iron sheet and bends it into a cylindrical tube and welds the long edge from end to end. Then he strengthens this tube by adding the metal hoops along the length of the tube, using the same technique explained above.
This technique of using straight staves and holding them in place with hoops was not a new idea. It was actually used centuries earlier for making wooden barrels to hold liquids. Hence, the name "barrel" also transferred to gun "barrels". This is true not only in the English language -- many other European languages also use the same words for "barrel" when referring to the wooden containers and the gun barrels.
So that's how the word "barrel" came to be used for guns as well.