I assume you mean Basic Training for the Army, and yes, you sign a legally-binding commitment to the US Government for at least two years before you leave for Basic.
There are medical and psychological reasons for which the military may choose to discharge you during or after Basic, but generally speaking, these aren't things that are up to you.