What is the difference between RUN and CMD in a Dockerfile? I am going to change my permission of files to 600. The following command works perfectly.

RUN /bin/bash -c 'chmod 600 /root/.ssh/config'


But this one failed

CMD /bin/bash -c 'chmod 600 /root/.ssh/config'


In the beginning, I thought the shell environment isn't bash so caused the error. However, adding bin/bash didn't solve the issue.
Note: Don’t confuse RUN with CMD. RUN actually runs a command and commits the result; CMD does not execute anything at build time, but specifies the intended command for the image. 

reference