Custom location for attached images

I would try changing your line in wp-config.php to

define( 'UPLOADS', 'media/blog/files' ); // where docker is mounted

Ie, get rid of the first /.

Let me know if this works.

EDIT

If you can’t change the definition of UPLOADS you could strip out the forward slash out with code. Try changing your code to this…

$upload_dir['path'] = str_replace( $upload_dir['basedir'], ltrim( UPLOADS, "https://wordpress.stackexchange.com/"), upload_dir['path'] );