To expand further:
It may seem arbitrary that the AI constantly DoWs you but if you pay attention to the clues available to you then you can either see it coming and prepare or outright avoid it. I think there are 3 main areas to keep in mind in order to handle diplomacy- the behavior flavor of the AI's leader, the demographics screen that ranks your civ in various metrics with military power being the most relevant here, and the diplomatic modifiers that keep track of your interactions with the AI.
First- there are certain civ leaders that just love to fight and depending on the circumstances it might just be inevitable. If you are unlucky enough to be on a continent surrounded by 3 or 4 of them then you may as well just prepare for non stop war. Shaka, Montezuma, Attila, etc. You'll learn to recognize them and prepare. Also note that them taking Authority first might indicate a predilection toward war.
Second- not having an adequate military at any point in the game (other than maybe the first 25-50 turns when the AI is too busy settling early cities to war) can make you the target of war. It's usually a good idea to be near your supply limit and to also check that you aren't too low on the military power ranking, ideally in the ballpark of the global average if possible. Even when playing a game where you intend to be peaceful you still need a military to avoid non stop wars. You might know you are safe with a small standing army because you are smart about using your units but the AI just sees a weakling that he can conquer.
Last- make sure you pay attention to the red/green diplomatic modifiers that appear when you hover over the AI portraits to get a clue as to who is a potential friend or foe and more importantly, why. A red modifier for border tension might be because you settled a city too close to them (or maybe they forward settled you because that's just what they like to do...). Social policy differences can also cause early game friction and even if you can't avoid that it is useful to see it coming and predict who is going to be a source of trouble.
What you have the most control over here are the green/positive modifiers. Embassies and open borders to create better relations. Actively trading with potential friends (you can even just straight give them 5GPT and get a strong positive modifier). Declarations of friendship with the right AIs (hint: maybe don't agree to friendship with an AI who has been denounced by everyone else unless he's the only friend you have left). Even intelligent use of denouncement can be a smart move as you can get positive modifiers with the other civs who dislike the target of your denouncement.
Later in the game, taking too many enemy cities can certainly get you labelled a warmonger, however, even that can be avoided if you are already friends with some civs and they happen to dislike the target of your conquest. Getting everyone to denounce your enemy or even join in the war against them can lead to less negative consequences. There are also mechanics in place that cause friction due to ideology choice or if you happen to be too far ahead of the AI in terms of winning- sometimes the price of success is being ganged up on by those that are jealous.
If you do find yourself in a war and want to end it sooner rather than later there are also things you can do to help. Try to up your war score against your enemy- kill units, pillage tiles, and take cities if needed. You can even raze a city or two as that has a bonus to war score. You can also bribe friends to DoW your enemy to make things easier on yourself and hopefully convince him that peace is in his best interest (and meanwhile get a "we fought against a common foe" modifiers with your friends!).
If you pay attention to all of these things and play the diplomacy game intelligently you can most assuredly play a relatively peaceful game with minimal war.