I agree with David Loeffler's answer: there is a large initial segment of algebraic number theory which essentially coincides with the study of Dedekind domains. A careful study of Dedekind domains gives an introduction to several important commutative algebra topics: e.g. localization, integral closure, discrete valuations, fractional ideals, and the ideal class group.
So one can motivate much of basic commutative algebra using concepts from algebraic number theory, but there is also a lot missing, for instance:
$\bullet$ Module theory. Modules over a Dedekind domain are "too nice" compared to modules over an arbitrary commutative ring. For instance injective = divisible and flat = torsionfree.
$\bullet$ The spectrum. The family of prime ideals in a Dedekind domain is unrepresentatively simple: all the nonzero ones are maximal. This is not a good motivation for spending time understanding the order-theoretic structure or the Zariski topology on $\operatorname{Spec} R$.
$\bullet$ Dimension theory.
$\bullet$ Primary decomposition. One can view primary decomposition in a Noetherian ring as a generalization of factorization of ideals into products of primes in a Dedekind domain, but once again the former is significantly more complicated than the latter.
$\bullet$ The Nullstellensatz.
Rather, if you study algebraic number theory and algebraic geometry at more or less the same time, you'll see that much of what you're doing is commutative algebra and that algebra will be well motivated. Among reasonably introductory texts I know of exactly one that pulls this off well: this text by my colleague Dino Lorenzini.
(Since my own commutative algebra notes have been mentioned, let me say that I view these notes as being at approximately the level of a student who has had a first, relatively nontechnical, course in either algebraic number theory -- e.g. from Marcus's text -- or algebraic geometry -- e.g. from Shafarevich's text -- and has been told that she needs to learn some commutative algebra before proceeding onward. On the other hand, my notes draw more explicitly on examples from topology and geometry than from either of the aforementioned areas.)
While studying analysis/calculus, I've found the following book to be quite interesting/motivating, even though I'm not so sure you can master the subject just by reading it alone:
Analysis by Its History, by Ernst Hairer and Gerhard Wanner.
Best Answer
The history of commutative algebra is mixed with the history of algebraic number theory and the history of algebraic geometry. It is actually mixed into the history of the ring concept as well, motivated by these applications. See