Dfx config / force local canister ID

Assuming my question regarding random canister ID is a feature and not a bug, I’m now wondering if there is a way to config / force dfx to use a specific canister ID when installing a canister locally?

For instance, as far as I know, the CMC canister must be deployed with the ID rkp4c-7iaaa-aaaaa-aaaca-cai so, is there a way to tell dfx to populate is to the local replica with this particular ID?

1 Like

See this changelog entry.

dfx canister create <CANISTER_NAME> --specified-id <PRINCIPAL>
dfx deploy <CANISTER_NAME> --specified-id <PRINCIPAL>

At the moment there is no way to specify it in dfx.json, but I know it is somewhere in our backlog to add this…

1 Like

Thanks. Great, it does the job (PR).

Was that announced and where is that documented?

I had a look to the CHANGELOG and portal but, probably did not look for the correct keywords, therefore had to ask.

I don’t remember if we made any announcements about that, but probably not. It’s just somewhere deep in the changelog…

Did a quick search on specified-id on the all portal, it does not seem to be documented at all.

It’s in the CLI references, but I agree it’s not discoverable at all.

1 Like

--specified-id <PRINCIPAL>: Attempts to create the canister with this Canister ID

Wait, that is not reliable?

If you try to create the same canister ID twice then it won’t work. I don’t think there’s any other likely failure sources except for bugs

Ah good to know. Thanks.