Book recommendations for commutative algebra and algebraic number theory
Solution 1:
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.)
Solution 2:
There's no law against reading more than one book at a time!
Although algebraic number theory and algebraic geometry both use commutative algebra heavily, the algebra needed for geometry is rather broader in scope (for alg number theory you need to know lots about Dedekind domains, but commutative algebra uses a much wider class of rings). So I don't think you can expect that there will be a textbook on number theory which will also teach you all the algebra you need for algebraic geometry.