Capturing JMX metrics from all containers on a host

As per official Java documentation, JMX client can use attach api to manage and monitor live java processes on the same host as JMX client. Does this work in a containerized environment wherein a host level agent scans processes (containers or bare-metal) on the same host, attach an agent if necessary and collect JMX metrics? My goal is to collect jmx metrics from thousands of containers using system agents. I cannot impose a requirement for client apps to expose JMX port using com.sun.management.jmxremote.rmi.port. A reference to open source code that does something similar will be a good starting point for me.