Shakespeare adopts a playful tone to describe the "seven ages" of man. He does so to underscore the transient and ever-changing nature of a growing person.
Every stage of man’s life has its distinctive peculiarities. After passing through adolescence, a person reaches adulthood. He takes up a profession. Shakespeare, here, picks up a soldier as he best describes the temperament of a man in this stage of life.
When a person becomes a soldier or attains adulthood, he develops a heightened sensitivity to others’ opinions about himself. His concern for his reputation acquires far greater significance than anything else. He becomes so obsessed with his repute that he doesn't even hesitate to risk his life to win himself glory. Shakespeare puts forth this in an amusing way:
Seeking the bubble reputation
Even in the cannon’s mouth.
"Bubble" signifies the idea of transience and impermanence. The “reputation,” for which a young man is eager to venture his life, is actually bubble-like; implying that it’s not going to last long.
It’s not considered prudent to endanger one's life for something that’s trivial or insubstantial. Life’s is too valuable to be lost for an insignificant cause. Shakespeare, however, isn't being didactic at all. He just points out, in a light-hearted manner, the peculiarity of a person at this stage of his life.