You need to store the image in a savebox and then wrap the caption into a minipage with the width of the box.
\documentclass{article}
\usepackage{graphicx}
\newsavebox\mysavebox
\usepackage{lipsum} % for example text only
\begin{document}
\lipsum
\begin{figure}
\centering
\sbox\mysavebox{\includegraphics[height=5cm]{example-image}}%
\usebox\mysavebox
\par
\begin{minipage}{\wd\mysavebox}
\caption{My very long long long long long long long long long long long long long long long long long long long caption }
\end{minipage}
\end{figure}
\lipsum
\end{document}

The adjustbox package simplifies this approach and also avoids "bad box" warnings if the image is larger then the usual text width.
\documentclass{article}
\usepackage{graphicx}
\usepackage{adjustbox}
\newlength\mylength
\usepackage{lipsum}
\begin{document}
\lipsum
\begin{figure}
\adjustimage{height=5cm, gstore width=\mylength, center}{example-image}
%alternative: \adjustbox{gstore width=\mylength,center}{\includegraphics[height=10cm]{example-image}}
\par% or empty line, needed to get caption below the image, not to the rigth
\adjustbox{minipage=\mylength,center}{\caption{My very long long long long long long long long long long long long long long long long long long long caption }}
\end{figure}
\lipsum
\end{document}
\documentclass{...}, the required\usepackage's,\begin{document}, and\end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – dexteritas Mar 21 '18 at 13:51