RUN - command triggers while we build the docker image.
CMD - command triggers while we launch the created docker image.
RUN EXPLAIN: RUN is an image build step, the state of the container after a RUN command will be committed to the container image. A Dockerfile can have many RUN steps that layer on top of one another to build the image. RUN: Commands May not Execute if Images are Cached. RUN instruction allows you to install your application and packages required for it. It executes any commands on top of the current image and creates a new layer by committing the results. Often you will find multiple RUN instructions in a Dockerfile.
CMD EXPLAIN: If a docker file has more than 1 CMD commands then all of them are ignored except the last one. As this command will not execute anything but just set the default command. Its mostly used to execute your start point. Eg. CMD ["npm", "start"]