Let $p>3$ be a prime, and let $q_p(2)=(2^{p-1}-1)/p$ be the Fermat quotient of $p$ to base $2$. In this note we prove that $$ \sum _{k=1}^{p-1} \frac {1}{k\cdot 2^k} \equiv q_p(2)-\frac {pq_p(2)^2}{2}+ \frac {p^2 q_p(2)^3}{3} -\frac {7}{48} p^2 B_{p-3}\pmod {p^3}, $$ which is a generalization of a congruence due to Z. H. Sun. Our proof is based on certain combinatorial identities and congruences for some alternating harmonic sums. Combining the above congruence with two congruences by Z. H. Sun, we show that $$ q_p(2)^3 \equiv -3\sum _{k=1}^{p-1} \frac {2^k}{k^3}+ \frac {7}{16} \sum _{k=1}^{(p-1)/2} \frac {1}{k^3} \pmod {p}, $$ which is just a result established by K. Dilcher and L. Skula. As another application, we obtain a congruence for the sum $\sum _{k=1}^{p-1}1/(k^2\cdot 2^k)$ modulo $p^2$ that also generalizes a related Sun's congruence modulo $p$.