The nation racked up a record $3.1 billion trade deficit last month, the Commerce Department reported yesterday, but officials cautioned that the deficit's size was exaggerated by the East and Gulf Coast dock strikes.

Nevertheless, it was the 17th month in a row that the United States has imported more than it has exported.

The mounting deficit, which is likely to hit a staggering $27 billion this year, is contributing to the decline in the value of the dollar abroad.

AT home the trade inbalance is boosting sentiment for measures to restrict imports.

A $27 billion deficit - the deficit already totals of $22.4 billion through October - would dwarf both last year's $5.7 billion and the previous one-year record of $6.4 billion set in 1972.

The Commerce Department's chief economist. Courtenay M. Slater, said yesterday that the big increase in the deficit - from September's $1.7 billion - was not an indication that the U.S. trade picture was getting worse.

However, she conceded, there is no suggestion that things are getting any better either. Exports rose sharply in September as shippers tried to beat the Oct. 1 dock strike deadline, then declined last month because of the longshoremen's walkout.

But when the "September and October figures are averaged together trade performance appears little changed from the previous six months," Slater said.

During the first 10 months of the year, "the deficit is running at an annual rate of $27 billion, reflecting heavy U.S. dependence on imported oil and relatively weak foreign demand for U.S. exports," according to Slater.

The Carter administration, which said last spring the deficit was little cause for alarm, has become increasingly concerned as the imbalance has shown few signs of narrowing.

U.S. ifficials have been pressuring European and Japanese leaders to stimulate their economies in order to boost demand for U.S. goods.

The administration has also put special pressure on the Japanese to relax their trade restrictions that make it hard for U.S. exporters to sell products in Japan, and United States is urging Japan to hold back on its shipments to the United States.

The U.S. trade deficit with Japan alone is running at an annual rate between $8 billion and $9 billion.

The dollar had been strengthening yesterday, but fell in most foreign currency markets when the record deficit was announced.

U.S. exports fell sharply from $10.9 billion in September to $9.2 billion in October. Imports declined slightly, from $12.6 billion to $12.3 billion.

A Commerce Department analyst said that the full impact of the strike on imports probably was not felt last month. While exports are recorded when they are shipped, importers have 10 working days to report to the Customs Service.

As a result, if imports were speeded up in late September, most of them probably would have been recorded by U.S. Customs in October, making last month's deficit seem larger than it was. Conversely, the $1.7 billion September deficit was probably understated.

The selective dock strike affects mostly items which are shipped in big containers, such as machinery, photo equipment and other high value items. Commerce Department officials said that it is difficult to estimate how much of U.S. shipping is affected by the dock strike, which may be settled this week. A 1974 study estimated container shipments accounted for between 15 per cent and 30 per cent of U.S. trade.

Commerce Department officials said that exports of most items declined, although there was increase in soybean sales abroad.

On the import side, about half the $300 million decline was accounted for by oil, which rises and falls from month-to-month but ranges between $3.5 and $4 billion a month.

There was also a decline in alcoholic beverage imports and steel imports, which may reflect heavy U.S. pressure on foreign steel makers to slow their shipments to the United States.