HiveBrain v1.2.0
Get Started
← Back to all entries
gotchaMinor

What is the difference between RUN and CMD in a Dockerfile?

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
thewhatdifferencedockerfilebetweenandcmdrun

Problem

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.

Solution

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

Context

StackExchange DevOps Q#8298, answer score: 3

Revisions (0)

No revisions yet.