16

I'm giving CosmosDB a chance and so I decided to build an app that uses it, but I'm running into this issue when using the emulator: Port is already in use.

I'm not sure where to reconfigure the port the emulator is pointing.

enter image description here

Dustin
  • 735
  • 1
  • 7
  • 16

7 Answers7

11

If you prefer just to change the Windows Shortcut, right click > properties and add /port=8082 (or whatever port number you want) at the end of the Target field after the quotes.

Note that in the Emulator Data Explorer, the URI field still showed the default port of 8081.

Shortcut properties

stu0292
  • 471
  • 4
  • 7
9

You can use /Port option to configure the emulator to listen to a different port.

https://learn.microsoft.com/en-us/azure/cosmos-db/local-emulator#a-idcommand-lineacommand-line-tool-reference

Siddhesh Vethe
  • 226
  • 1
  • 3
  • Thanks for the reference. This worked. Also worked to simply restart my computer. The ports got reassigned automatically to different ones. – Dustin Jul 03 '17 at 20:05
6

I had a similar problem, where i got an error "port 10253 already in use" which is a port for Direct connectivity. Direct connectivity port defaults for CosmosDB are 10251,10252,10253,10254.

Used the following Command-line Syntax to change the default port and it worked,

CosmosDB.Emulator.exe /DirectPorts=10261,10262,10263,10264


OR (in my case)


"C:\Program Files\Azure Cosmos DB Emulator\CosmosDB.Emulator.exe" /DirectPorts=10261,10262,10263,10264

Note: You can use port of your choice, but make sure that they are not already in use

MechanicalCoder
  • 286
  • 1
  • 10
4

The CosmosDbEmulator comes with a PowerShell module, which you can use to control it.

To get started using the module run the following command:

 Import-Module "$env:ProgramFiles\Azure Cosmos DB Emulator\PSModules\Microsoft.Azure.CosmosDB.Emulator"

Start the CosmosDbEmulator on a port of your choice, e.g 8082 as follows:

Start-CosmosDbEmulator -port 8082
Mwiza
  • 7,780
  • 3
  • 46
  • 42
1

I finally got it working with powershell.

Import module

$env:PSModulesPath += "$env:ProgramFiles\Azure Cosmos DB Emulator\PSModules"
Import-Module Microsoft.Azure.CosmosDB.Emulator

Stop CosmosDB emulator

Stop-CosmosDbEmulator

Start CosmosDB emulator with prefered port

Start-CosmosDbEmulator  -Port 10101

And I got it working... Hope this helps.

Bryan van Rijn
  • 837
  • 10
  • 18
  • 1
    For me the first import module command had to be a bit different: `$env:PSModulePath += ";$env:ProgramFiles\Azure Cosmos DB Emulator\PSModules"` – Konrad Jamrozik Feb 24 '20 at 20:45
1

With the latest (2.14.3) that I installed today, you need to specify /mongoport instead of /port.

enter image description here

Jonathan Brown
  • 3,644
  • 3
  • 25
  • 31
1

Check your processes list and find one like Microsoft.Azure.Cosmos.GatewayService.exe. Kill it. Then I can start Cosmos emulator.

fkpwolf
  • 373
  • 4
  • 13