Sometimes it is clear to me that "only" and "just" can be used interchangeably, for example:
It is only/just a few minutes away from the station.
Only/just two students came to class on the day before Christmas.
And it is clear to me that sometimes "just" is the only option when it means "very recently".
But are there occasions when only "only" can be used? Is the rule that you use "only" when it is used as an adjective? For example, in the first sentence below I'm very sure we can't use "just":
This is the only photograph I have of my great grandfather.
However for the following example is the only option also "only" or can I also use "just"?
I went to the supermarket and there was only one cookie.
I went to the supermarket and there was just one cookie.
Both sound Ok to me but perhaps the final example with "just" is incorrect? Or if not what are the rules around this please?
Thank you