Use the composition depth buffer in order to create a depth of field. This modifier use the focus distance of the
Camera
You can vizualize the depth of field with colors by checking this option:
Go check
Legacy Blur part of the documentation for further details about the parameters.