I will be in San Francisco this summer.
I would love to sit by the sea and watch some big container ships passing by.
Is there some nice place where you can do that?
It wouldn't hurt if there is a cafe nearby ;)
Container ships frequently enter the bay, but there isn't a continuous stream of them, so you may be waiting for a while for optimum viewing. You might want to use a ship tracking website (such as this one) to see what is coming in and out. This will show smaller vessels as well, but if you click on each ship, it will tell you its name and type, and often show a picture.
You can see container ships pretty much anywhere with a good view of the bay. The only way in or out is through the Golden Gate, so it makes sense to focus your viewing there, plus you get the most picturesque views with the bridge. There are also good views of ships going under the Bay Bridge from San Francisco's eastern waterfront, including a number of bars and restaurants, but you run the risk of missing some ships this way, such as tankers headed to the northern ports.
The Golden Gate Bridge - if you're in the right place at the right time, you can look down on the ships right as they pass under you. There is a cafe, though it is rather expensive as it caters to cold and/or hungry tourists.
Crissy Field is a long park on San Francisco's northern waterfront. It's easy to have a view like this where you won't miss container ships coming under the bridge. There's a small cafe called the Warming Hut. You can head west and uphill from Crissy Field to the Battery East Vista for a higher angle view, though you'll be farther from the cafe.
Get out on the water. You could take a bay cruise or just ride the ferries (consider paying the few dollars for a Clipper card, which works on most all public transit, for a discount over the cash fare, especially if you'll be using transit elsewhere during your trip).
In addition, the Port of Oakland operates a small park called Port View Park (h/t: Quora). According to the website, "the location affords great views maritime operations at the Ben Nutter terminal and of the bay." It is, however, difficult to get to (I would personally very much recommend against the walk through the heart of West Oakland, especially if you're unfamiliar with the area), but you could get someone to drive you there if you're interested.
Finally, keep an eye on the weather. The fog will come in and stay in, especially during summer, and views from high places will be non-existent. A lounge with a great view suddenly just becomes a place to get a very expensive drink and see nothing. It will quickly become cold and damp, surprising many tourists and inspiring sales of overpriced sweatshirts, a vital part of our local economy.