How does locking work?

I want to lock a chest but it says it needs a key. I already pre made a key but how do I set that key as the key for the chest? (it's a container btw)

This topic is now closed. Topics are closed after 60 days of inactivity.