I'm going to throw my 2 cents in here as well. As a former serviceman here in the states I can testify to the validity of the mindset of individuals joining Starfleet. I'll list the reasons and then discuss some afterwards. And yes, these were pretty much all hit on in the comments above.
- Familial legacy or duty (my father, grandfather, brother uncle, etc. served)
- National pride or national duty (serving of fighting for my county)
- Educational benefits (College tuition)
- Satisfying a sense of adventure, (see the world)
- Exploration (rare now but think of Lt. Charles Wilkes discovering Antarctica)
- Alternative form of punishment or intervention for at risk youth (rare)
- Skill, trade and training opportunities.
- Stable career (economic hardships)
I'm certain I may have missed a few but these are the stand out reasons, and most are valid for the Star Trek universe as well.
Personally, I joined the service for 3 reasons, 1, national pride, I'm proud of my country and I wanted to give back in a way I knew was of value. 2, Familial duty, my father and both grandfathers served and my father saw combat in Vietnam, I felt it was my duty to carry on that legacy. 3, Education, I knew I could get a decent education while serving my country. Not for a second did I consider wealth while serving.
In the Star Trek universe the pursuit of wealth and fortune in the realm of the Federation is a distant memory. Since everything someone needs for day to day living is now taken care of, people can focus on experiencing and expanding the human condition. Knowledge, exploration and adventure are the currency of the day.
All people who join the Star FleetStarfleet know there is the inherit possibility of death, just as in our modern military. No one joins without this being made abundantly clear long before ink is placed on paper. With that said, the Federation and Starfleet is not by nature, war mongering. They are adventurers, scientists and explorers who only thirst to further those desires. The realities of the Galaxy however, have shown prudence is necessary when encountering other cultures who's goals are counter to that of the Federation.
Most starships are exploration vessels first, weapons are strictly considered defensive but are quite capable of being used in an offensive role. Sun Tzu said it best "Invincibility lies in the defense; the possibility of victory in the attack."
The Galaxy is full of danger. Just being in space is dangerous enough, let alone crossing paths with most life forms throughout, not just the intelligent kind. It comes with the job and I'm quite certain everyone in Starfleet is very prepared for the realities of their choice.