Since Pi-hole v6, its settings live in /etc/pihole/pihole.toml, and pihole-FTL --config changes them from the shell. That includes the local DNS records you would otherwise add one by one in the web interface.
sudo pihole-FTL --config dns.hosts '[ "192.0.2.20 nas.home.example", "192.0.2.30 printer.home.example" ]'
Each entry is an IP address and a host name in one string, the same format as a hosts file. The docs show the general pattern as --config key.name value, so the same command sets other options too, for instance sudo pihole-FTL --config dns.dnssec true.
There is a big trap. The value is the whole list. Running it with one record replaces all records that were there, so copy the existing ones into your command first. I’d check the Local DNS Records page in the web interface before running it, or keep the list in a script so it is always complete.
In Docker, the same thing goes through the container:
docker exec pihole pihole-FTL --config dns.hosts '[ "192.0.2.20 nas.home.example" ]'
Names you set here only work for clients that use Pi-hole as their DNS server. Test with nslookup nas.home.example from such a client.
For CNAME records there is a matching key, dns.cnameRecords.
Further reading: Pi-hole FTL configuration file