Get the post ID and display the images

As far as I know get_field() function will return the response according to the current post (There’s no need to specify the post ID). But if you want to specify the post ID then you have to type it in the second argument, like:

get_field( $selector, $post_id );

So your code would be like this:

<?php

global $post;

$post_id = 0 !== $post->ID ? $post->ID : false;
$images  = get_field( 'gallery', $post_id );

if ( $images ): ?>
// Your content.
<?php endif; ?>

Do not use $post->ID directly in the second argument because the value might be 0 sometimes if WP_Query fails. If that happens use false to target the current post.

Check the resources:

https://www.advancedcustomfields.com/resources/get_field/