In "Duty: Memoirs of a Secretary of War," Gates recounts how Obama appeared to lack faith in a war strategy he had approved and in the commander he named to lead it, according to The New York Times and The Washington Post. He said the president also did not like Afghan President Hamid Karzai.
"As I sat there, I thought: the president doesn't trust his commander, can't stand Karzai, doesn't believe in his own strategy and doesn't consider the war to be his," Gates writes of a March 2011 meeting in the White House.
"For him, it's all about getting out."
Having approved deploying more than 30,000 forces after an acrimonious White House debate, the US president seemed plagued by doubts and surrounded by civilian aides who sowed distrust with the military, Gates writes.
Obama was "skeptical if not outright convinced it would fail," Gates writes in the memoir, which is due to be released on January 14.
In contrast to his subdued, even-keeled public demeanor as Pentagon chief, Gates strikes a sometimes bitter tone in his memoir.
The former CIA director whose career dates back to the Nixon administration voices frustration at the "controlling nature" of Obama's White House, which he says constantly interfered in Pentagon affairs, even though civilian aides lacked an understanding of military operations.
The White House national security staff "took micromanagement and operational meddling to a new level," he writes, comparing the approach to the 1970s Nixon era.
"All too early in the administration," Gates writes, "suspicion and distrust of senior military officers by senior White House officials -- including the president and vice president -- became a big problem for me as I tried to manage the relationship between the commander-in-chief and his military leaders."
After a tense meeting on Afghanistan in September 2009, Gates says he came close to resigning because he was "deeply uneasy with the Obama White House's lack of appreciation -- from the top down -- of the uncertainties and unpredictability of war."
A statement from National Security Council spokeswoman Caitlin Hayden later defended Obama's record on Afghanistan.
"It is well known that the president has been committed to achieving the mission of disrupting, dismantling and defeating Al-Qaeda, while also ensuring that we have a clear plan for winding down the war," she said.
Hayden also hit back at Gates's assertion that Vice President Joe Biden had been "wrong on nearly every major foreign policy and national security issue over the past four decades."
"The president disagrees with secretary Gates's assessment... Joe Biden has been one of the leading statesmen of his time and has helped advance America's leadership in the world," she said.
A White House official separately defended Obama's record on both Afghanistan and Iraq.
"It's well known that as a matter of principle and sound policy, President Obama opposed going to war in the first place, opposed the surge of forces and then ended the war in Iraq as president. Any suggestion to the contrary is simply wrong," the official said.
On Afghanistan, the official said Obama "has always been firmly committed to the strategy that secretary Gates helped designed and that our troops have so ably carried out in Afghanistan, while also insisting that we have a clear plan to wind down the war."
Gates, however, gives credit to Obama for approving the raid on Osama bin Laden's compound in Pakistan, which he himself initially opposed.
It was "one of the most courageous decisions I had ever witnessed in the White House," the former Pentagon chief writes.
Although Gates heaps praise on former secretary of state Hillary Clinton, he is stunned by an exchange between Obama and Clinton in which the two openly admitted they opposed a troop surge in Iraq in 2007 for purely political reasons.
"To hear the two of them making these admissions, and in front of me, was as surprising as it was dismaying," he says.
Gates helped oversee the deployment of additional troops to Iraq during the Bush administration.
A Republican, Gates served under ex-president George W. Bush and was asked to stay on at the Pentagon for two years after Obama entered office.