Is $dW = -pdV$ always valid? Suppose the case that a fluid is kept in a closed container which is now shaken. The volume won't change but work will be done.
Then how can the formula $dW = -pdV$ be valid for every isochoric process? Or is the shaking of a fluid in a closed container not a thermodynamic process? I am confused.
 A: Shaking the container is indeed a way of doing work on the system.
All physics adopts idealizations of one kind of another. In thermodynamics we first identify the system we are interested in, and then we make an idealized model of it. A commonly used model in entry-level thermodynamics is when the internal energy of the system can only be increased in only two ways: by supplying heat, or by doing one kind of work. Such a system has only two terms in the fundamental equation, such as
$$
dU = T dS - p dV .
$$
When there are just two terms like this, we say we have a "simple system". When the work term is $-pdV$ we say we have a "simple mechanical system".
The shaken container is a mechanical system but not a simple mechanical system. The model in terms of pressure and volume is simply not adequate to describe the kind of work one can do by shaking. So we make the model more realistic. In the case of shaking there is no very easy way to do this because the turbulent motion is to do with abrupt changes in the forces on the container, and the inertia of the fluid. However one can easily model smoother processes such as stirring, by introducing an angle $\phi$ of a paddle wheel and a torque $\tau$, and writing
$$
dU = T dS - p dV + \tau d\phi.
$$
In the case of a fluid the thermal equilibrium states will all have $\tau = 0$ but for a solid they needn't.
The main idea of this answer is not that you worry about this example of stirring, but rather get a clearer picture of the idealizations which are involved in choosing to model a system as a simple mechanical system. In fact what we often do, in the case of stirring a fluid, is not to bother to write the $\tau d\phi$ term explicitly, but simply note that once some added internal energy has been provided, by whatever means, we no longer care about how it was provided. One can then model the fluid using just $p$ and $V$, and accept that the model cannot be applied to the system during the stirring process itself, but it can be applied to the initial and final states (as long as the amount of fluid has not changed). Another standard example of this idea is the free expansion, when a gas rushes into a previously evacuated space. In that process the gas volume changes but no external work is done.
A: The shaking of the fluid is not $pdV$ work. It's a different kind of work called "stirrer work" or "shaft work". It's the kind of work that is done when you stir your coffee with a spoon.
James Joule's famous experiment to show the equivalence between mechanical work and heat involved stirrer work, in which he used a brass paddle wheel stirring water in a copper vessel. To learn more, see this: https://www.aps.org/publications/apsnews/201506/physicshistory.cfm
Hope this helps.
A: $δW=-PdV$ is the expression of the work of a pressure force on a surface of an isotropic, non-moving fluid. For the general expression of mechanical work, you have to use the definition $$δW=\mathbf F\cdot \mathbf{dl}$$  where $\mathbf{dl}$ is the displacement of the point of the system where the force is applied. For a surface (volume) force, you have to integrate over the surface (volume) of the considered system.
If you can represent the internal state of the system (with respect to that force) by a pair of extensive-intensive variables X,Y and if you choose wisely those variables, the work is given by Y dX. This is the case for a point force above, for pressure forces, but also for magnetization ($δW=BdM$), for mechanical stresses ($σdε$, but note that those variables may be tensors), for electrical work, etc.
It is obviously impossible do so for the stirring of a fluid, except for the slow stirring of a highly viscous fluid. Remember, thermodynamics is only valid close to equilibrium.

Note also that when applying the 1st principle, changes in kinetic energy of the whole system have to be taken into account when relevant ; those take up some of the mechanical work.
A: Work in context of closed systems is any energy exchange between the system and surrounding that is not considered as the exchange of heat, as $$\Delta U = W + Q$$
( with "done on the system" convention).
There can be both "volume" and "non volume" work. E.g. battery charging, elevation of internal potential energy or mentioned stirring are few kinds of non volume work.
