Yes, you can apply the formula $\Delta U$=nCv$\Delta T$ for an ideal gas in a container whether or not the process is isochoric.
This is because the change in internal energy for an ideal gas undergoing some mechanical process is mainly affected by the change in kinetic energy of the gas. It does not depend on the change in volume of gas.So as long as the temperature difference is same the change in internal energy will be same. Heat capacity is the amount of heat required to raise the temperature of a substance by 1 unit so $\Delta U$ is directly proportional to heat capacity and $\Delta T$ along with the number of moles of gas.
When the process is carried with constant volume only then $\Delta W$ is $0$ so in that case $\Delta Q$=$\Delta U$ whereas $\Delta U$=nCv$\Delta T$ holds good always for an ideal gas under some mechanical process.