Homemade salad dressing separates into layers after it sits for a while. Why doesn't this violate the 2nd law of thermodynamics? The oil, vinegar and other liquids in homemade salad dressing separate into layers after sitting for a while, making the mixture become more organized as time evolves.  Why doesn't this violate the 2nd law of thermodynamics?
I assume that the answer is that since the separation is due to gravity, the effect is due to an external force and so the system isn't closed which is necessary for the 2nd law, but I'm not sure.
If that's the answer, then what happens if I consider the whole system include the salad dressing, gravitational field and whatever mass is generating the gravitational field?  The entropy of the salad dressing seems to decrease and so the entropy of some other component of this system must be increasing, but it's hard to see what this other component would be.
 A: Here is an attempt to connect two of the other answers:
The system is the salad dressing, which is in contact with air that forms a heat reservoir at constant temperature $T$ (isothermal).  Everything is also at constant pressure $P$ (isobaric). We're comparing the initial, mixed with the final, separated states of the system.

DavePhD states that the demixing occurs because the result has lower energy, which sounds definitive.  However, the dressing's loss of energy is the reservoir's gain (by conservation of energy), so the total energy is unchanged, and one might start to feel a bit uncertain.
He then states (correctly) that the change in Gibbs free energy:
$$ \Delta G_{sys} = \Delta H_{sys} - T \Delta S_{sys}  $$ 
must be negative for the reaction to proceed spontaneously, noting that "entropy (S) is only part of the consideration".  I have added subscripts to indicate that these quantities are the Gibbs free energy, enthalpy, and entropy of the system.  
At this point, someone trained to believe that entropy must always increase may be rather befuddled.

Recognizing this potential confusion, SteveB connects this result to the total entropy of the system plus reservoir.  For an isothermal, isobaric process, whether or not the system performs work, $\Delta H_{sys}$ is the amount of heat added to the system from the reservoir.  Therefore, the change in entropy of the reservoir (not of the system + reservoir) is:
$$ \Delta S_{res} = - \frac{\Delta H_{sys}}{T} $$
The change in total entropy $S_{tot}$ is then:
$$ \Delta S_{tot} = \Delta S_{sys} + \Delta S_{res} = \Delta S_{sys} - \frac{\Delta H_{sys}}{T} = - \frac{\Delta G_{sys}}{T} $$
So, for an isothermal, isobaric reaction, a decrease in Gibbs free energy of the system is equivalent to an increase in total (system + reservoir) entropy.  As expected (hoped for?), spontaneous reactions do indeed increase (total) entropy!
Note that de-mixing is not necessarily spontaneous:  the de-mixing process must generate sufficient heat to raise the entropy of the reservoir by more than the decrease in entropy of the system. 

Finally, if the process is isobaric but not isothermal, some of the emitted heat raises the temperature (and hence entropy) of the system (as stated by SteveB), so the calculation is no longer so simple.  In fact, $ \Delta G_{sys} = 0 $ is no longer the threshold for spontaneous reactions in this condition, because for an infinitesimal, reversible process:
$$ dG = -S \, dT + V \, dP $$
so $dG \ne 0 $ if $dT \ne 0 $.  Instead, the change in total entropy must be calculated to determine spontaneity.
A: Short answer:
The short answer is that the transition from mixed salad dressing to two layers is exothermic, and this heat release creates an entropy increase. For all intents and purposes, the process is analogous to an exothermic chemical reaction, like combustion.
Similarly, a container filled with ball bearings can spontaneously settle into a hexagonal close-packing arrangement. Like the salad-dressing case, this gives the visual appearance of greater order, but in fact it is not a violation of the law $\Delta S_\text{univ}\geq 0$, as energy is released upon settling, which is converted into disordered heat.
Slightly longer answer:
I'm terrible at thermodynamics so there may be several corrections needed to make the following rigorous, but you can try to make things explicit as follows: let the salad dressing be contained in a rigid, thermally-conducting container under the influence of gravity. The total energy of the system can be written as
$$U=m_\text{w}\overline{U}_\text{w,bulk}+m_\text{o}\overline{U}_\text{o,bulk}+\int_V\rho(\mathbf{r})V(\mathbf{r})\,d\mathbf{r}+\int_{S_d}\gamma_\text{w,o}\,dS+\int_{S_c}\gamma(S)\,dS$$
where $\overline{U}_\text{w,bulk}$ is the total bulk internal energy per mass of the water (and similar for $U_\text{o,bulk})$, $m_\text{w}$ and $m_\text{o}$ are the total water and oil masses, $\rho(\mathbf{r})$ is the liquid density at location $\mathbf{r}$ in the container, $V(\mathbf{r})$ is the gravitational potential, $S_d$ is the set of oil-water interfaces, $\gamma_\text{w,o}$ is the oil-water surface tension, $S_c$ is the boundary of the container walls, and $\gamma(S)$ is the liquid-wall surface tension of the type of liquid at boundary location $S$.
In essence, the first and second terms describe the bulk (volumetric) energy of the water and oil, the third considers the gravitational energy of the system, the fourth considers the energy due to the oil-water interfaces, and the fifth considers the energy due to the liquid-container interface.
Linearizing gravity as $V(\mathbf{r})\approx g|\mathbf{r}|$, $U$ can be rewritten as
$$U=m_\text{w}\overline{U}_\text{w,bulk}+m_\text{o}\overline{U}_\text{o,bulk}+\rho_\text{w}m_\text{w}\langle h_\text{w}\rangle+\rho_\text{o}m_\text{o}\langle h_\text{o}\rangle\\+\gamma_\text{w,o}A_d+\gamma_\text{w,c}A_{\text{w,c}}+\gamma_\text{o,c}A_{\text{o,c}}$$
where $\langle h_\text{w}\rangle$ and $\langle h_\text{o}\rangle$ are the expectation values of the water and oil height inside the container, $A_d$ is the total oil-water droplet interface area, and $A_{\text{o,c}}$ and $A_{\text{w,c}}$ are the total areas of contact the oil and water make with the container walls and $\gamma_\text{w,c}$ and $\gamma_\text{o,c}$ are the water-container and oil-container surface tensions.
A change of configuration creates a change in internal energy
$$\Delta U=\rho_\text{w}m_\text{w}\langle \Delta h_\text{w}\rangle+\rho_\text{o}m_\text{o}\langle \Delta h_\text{o}\rangle+\gamma_\text{w,o}\Delta A_d+\gamma_\text{w,c}\Delta A_{\text{w,c}}+\gamma_\text{o,c}\Delta A_{\text{o,c}}.$$
Note that $\Delta U<0$ for a transition from mixed salad dressing into two separated layers.
The excess energy is converted into heat, ie $\Delta U=\Delta q$, which is then lost to the surroundings through the container walls. The entropy change is then
$$\Delta S=\Delta S_\text{sys}+\Delta S_\text{surr}=-\frac{\Delta U}{T_\text{sys}}+\frac{\Delta U}{T_\text{surr}}>0$$ since $T_\text{sys}>T_\text{surr}$ for heat transfer to occur.
(Apologies if I botched up the fundamental thermodynamic relations in the previous paragraph).
A: The separation does not violate the 2nd law of thermodynamics, because the oil and water phases being separate is a lower energy state. 
The water molecules strongly interact with each other, forming hydrogen bonds.  The protons of water are shared between two oxygen atoms of two different water molecules, forming a constantly changing network of molecules.  Water molecules do not have strong intermolecular interactions with oil molecules.  
The more the two phrases are mixed, the more water molecules are at an interface surface.  The water molecules at an interface surface can not fully participate in intermolecular interactions with other water molecules, so this is a higher energy state.  
For a process to spontaneously occur, the Gibbs free energy (G) must decrease.
$\Delta G = \Delta H-T\Delta S$
So entropy (S) is only part of the consideration.  Enthalpy (H) and temperature (T) must also be considered.  In this case the decrease in enthalpy (H) due to energy of intermolecular interactions makes up for the decrease in entropy (S).  The process is an exothermic process.  
Even absent gravity, it is still thermodynamically favorable for the phases to separate, to minimize the interfacial surface area, just like a spherical drop of water being the lowest energy state absent gravity.  
I would predict that absent any gravity, the lowest energy state of the salad dressing would be a sphere of water phase surrounded by a spherical shell of oil phase.  
A: My view is simpler, on the lines you already quote  of the mixture in the  container not being an isolated system.
The same as with crystals coming out of solution one has to consider the whole system when quoting the second law. In this case there will be heat exchanged with the environment as well as radiation, as molecules fall into the  lower energy state that characterizes the separation, thus not closed.
A: Answer without the math:
The counterintuitive part here is the mistaken assumption that the state of seperation with "pure" vinegar and "pure" oil represents the higher energy or more "ordered state" than the blended vinegar and oil. 
That's backwards. The "pure" states are the lowest energy states and mixed the highest. 
You add energy to the vinegar/water and oil system when you whisk the the components together. The mechanical impact of the whisk actually crams the water and oil components together into highly complex structures. 
By analogy, the seperated state is like having a bunch of rocks laying on the ground. The whisk picks the rocks up and piles them into structures. Since entropy causes the rocks to seek a lower energy state (the ground) the rock structure eventually falls apart. 
These structures are on the microscopic level (size of living cells) instead of the nanoscopic (molecular) level but they function like springs storing the energy imparted by the whisk. The structures don't pop apart immediately because friction like forces of the opposing attractions of water trying to stick to water while repealing oil and the oil trying to stick to oil while repealing water. 
You can think of it like a keystone arch with water-water attraction being the rock resisting compression and the oil-oil attraction being gravity. (Except it all occurs in three dimensions.) In the arch, the balance of gravity and compression make the arch stable. The salad dressing "arches" are likewise stable for a short time. 
Molecular motion eventually causes the structures to move out of alignment, like shifting a stone in an arch, and the structures collapse releasing their stored energy. That stored energy then moves the water and oil back to their separate layers. 
So the system goes separated(low energy)-->whisked(high energy)-->separated(low energy.)
Gravity doesn't add much to the process because the separation process is driven by the energy added by the whisk in the blending. Gravity just causes denser of the two to the bottom of the container. If you made salad dressing in zero gravity, it would still separate into two blobs its just that they would orientated to each other more less randomly instead of top to bottom. (They studied just this effect, because of its chemical importance on the Space Shuttle and International Space station back in the 90s.)
Bottled salad dressing don't seperate because they use emulsifier, usually lecithin, which act like a glue (or mortar in the arch analogy) making it hard for the microscopic spring structures to pop apart. However, given enough time, even those will separate. 
Energy stored in hydrophilic-hydrophobic combination systems plays a big role in biochemistry e.g. it is the foundational dynamics of all biological membranes. Back in college we calculated how much energy would be released if you could magically cause all your bodies membranes to collapse at once. Don't remember the exact number but I do remember it was a surprisingly big boom. 
A: 
Oil consolidates in water because that increases entropy $S$.  It rises to the top because that decreases enthalpy $H$.  When both actions happen together, it reduces the Gibbs free energy $G$.
$$\Delta G = \Delta H - T \Delta S$$
As DavePhD noted, hydrogen bonds form between pairs of water molecules.  As Aaron Stevens commented in a duplicate question, "polar water molecules have more configurations to make hydrogen bonds with their neighbors."
In particular, if there are $N$ water molecules in the container, a given molecule has $N$ possible ways (thermodynamic states) to make one hydrogen bond.  (Technically, $N-1$ because a molecule can't bond with itself, but with a large number of molecules, the distinction isn't important).  
If a water molecule makes two hydrogen bonds, there are now $N^2$ ways to do it.  With three hydrogen bonds, $N^3$ ways.  You can see that as more hydrogen bonds form in the container, more thermodynamic states are possible.  This increases the entropy.
Hydrogen bonds don't form between oil and water, nor between two oil molecules.  When a water molecule is surrounded by oil, it makes fewer hydrogen bonds and the total entropy goes decreases.  Thus, the entropy is maximized by consolidating (gathering) the oil together into a contiguous mass, so the water makes the minimal amount of contact with it.
This is illustrated in the following pictures, from a simulation I wrote to answer this question.  The hexes are molecules, 90 water (cyan) and 10 oil (yellow).  The border between the molecules are drawn in blue if it forms a hydrogen bond, and white if not.  The total number of hydrogen bonds are displayed at the bottom of the simulation.
Examine the picture at the top of this answer.  The oil is mixed well with water, and the water forms 201 hydrogen bonds.
As the oil begins to consolidate, water molecules can form more hydrogen bonds (now 212) with each other:

When the oil is fully consolidated, the maximum number of hydrogen bonds (233) can form:

You can see that the number of hydrogen bonds -- and thus the entropy -- is maximized when the oil is consolidated.
Oil floats (rises to the top) because of enthalpy.  Specifically, the potential energy of the mixture is the combined gravitational potential energy of the molecules.  This is minimized by putting the oil above the water.
In the absence of gravity, oil will consolidate but not float.  However, when gravity is present, both effects will happen in order to minimize the Gibbs free energy.

Addendum: "In the absence of gravity, oil will consolidate but not float."  International Space Station experiments bear this out:

Colloid-polymer mixtures:
  The results from the ISS experiments studied the spinodal decomposition, or phase separation near the critical point, unencumbered by density differences of the phases. The growth of the phase separation was studied using both light scattering and imaging. Without gravity, the phase separation took 30 times longer than on Earth. The sample was mixed, then phase separation began, gradually coarsening until the container walls interacted with the mixture (at 42 hours) and the colloid-rich phase wet the container wall, completely coating it after 60 hours. 
Colloid-polymer critical point: Immediately after mixing, the colloid-polymer critical point sample began to separate into two phases?one that resembled a gas and one that resembled a liquid, except that the particles were colloids and not atoms. The colloid-poor regions (the colloidal ?gas? phase) grew bigger until, finally, complete phase separation was achieved and there was just one region of each?a colloid-rich phase and a colloid-poor phase. None of this behavior can be observed in the sample on Earth because sedimentation would cause the colloids to fall to the bottom of the cell faster than the de-mixing process could occur. Knowledge gained from these runs was used to develop the BCAT-3 later operated on ISS.
EXPRESS Physics of Colloids in Space

A: DavePhD's answer explains the specifics. The separation decreases the enthalpy of the oil-water mixture. But there's one more step:
When the enthalphy of the dressing decreases by $\Delta H$, it causes the entropy of the dressing and its surrounding environment to increase by $\Delta H / T$.
The reason is: The decrease in enthalpy releases heat, which (slightly) increases the temperature of the dressing, and its container, and the room its in. Higher temperature means more entropy.
So in the bigger picture, it really is increasing the entropy.
A: I think most of these explanations are wrong. 
Fluids stratification isn't driven by bonding interactions - these simply govern the rate and lossiness of the process. In principle, the stratification could be loss-free - an inviscid emulsion would still stratify, so the lovely Wikipedia formulae above would become trivial and uninstructive. I think the answer is actually a lot simpler.
Stratification is just Archimedes' principle. Houses get messy since there are more ways of them being messy than tidy. Imagine a house littered by toys and pans. If a human comes along and links all the toys to a point in the playroom with elastic ropes, and too with all the pans with the kitchen, letting the ropes go and all the toys fly roughly into the playroom, and all the pans skid along the floor into the kitchen. The house is technically tidier since there are fewer ways of arranging items in their correct room than in the whole house. Of course, the human who wound the ropes has to degrade their muscular sugars to do this, as did the process which mixed the said emulsion (think pushing a balloon underwater). Stratification is just the release of stored potential energy which originated in the mixing process, which itself originally required work. Any mess can be tidied by applying work - it's just this ultimately creates more mess.
