RAM disks - can I use APFS and/or compression?
@klanomath has the correct command in the comments above.

diskutil partitionDisk $(hdiutil attach -nomount ram://SIZE) 1 GPTFormat APFS 'RAMDisk' '100%'


My results:

$ diskutil partitionDisk $(hdiutil attach -nomount ram://12128430) 1 GPTFormat APFS 'RAMDisk' '100%'
Started partitioning on disk15
Unmounting disk
Creating the partition map
Waiting for partitions to activate
Formatting disk15s2 as APFS with name RAMDisk
Mounting disk
Finished partitioning on disk15
/dev/disk15 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        +6.2 GB     disk15
   1:                        EFI EFI                     209.7 MB   disk15s1
   2:                 Apple_APFS Container disk16        6.0 GB     disk15s2