For me,
This worked
docker run --name <container_name> -p 27018:27017 <mongodb_image>
Assuming port 27018 is not running any process
When it runs, in MongoDB Compass in
Add New Connection: mongodb://localhost:27018 -> Mention the first port number you used for docker run command