Port number for locally running replica

I started a dfx instance with dfx start. In the first couple lines, it prints out the replica’s address (e.g. http://localhost:56829/). But then it fills the scrollback as the replica runs and eventually I can’t scroll back to that line. How do I find the address of a locally running replica?

I tried using dfx start --host to specify where I wanted the replica to be located at, but it still uses a random port. Running dfx start --host 127.0.0.1:54321 prints at the end:

binding to: V4(127.0.0.1:54321)
replica(s): http://localhost:60061/

I’m not sure what the ‘binding to’ line implies, because the replica is only available at http://localhost:60061/, not http://localhost:54321/

You can look under .dfx/replica-configuration/ in your project directory. You should find it hiding there.

(There are actually two servers running, you could set them up individually using the dfx replica and dfx bootstrap commands)

Awesome, thanks!

Is there any way to specify what port to use?

edit: I was able to specify the port by running dfx bootstrap --port 54321. This seems to do everything I need. What server does the dfx replica call start? What will I miss out on by starting using dfx bootstrap --port 54321 instead of dfx start?

The port you’re specifying there is for the frontend. That’s the ‘binding to’ port in your first post.

dfx replica runs the actual IC replica, the bootstrap server is serving the frontend, including assets. Was it the frontend port you want to change? (If it is you can set it in dfx.json under local.bind and just run dfx start as normal)

Ahh, got it. My current work is on the backend (replica), so I’ll just use dfx replica --port 54321 for now.

To clarify, I can expect that running these two commands will do everything that dfx start does, but will allow me to specify my ports:

dfx bootstrap --port 12345
dfx replica --port 54321

It will, but you’ll need to point the bootstrap at the replica with the --network flag. You’d also need to point dfx canister calls at the replica using the network flag too; you used to be able set the port for this in dfx.json, and just use the canister commands as normal, but I don’t recall where the key for this moved to in recent versions.