DockerFile could not execute Shell / Exec Form of CMD - RUN

Hi,

I have separate docker files having below commands which are not working
RUN [“apt-get”,“update”,“&&”,“apt-get”,“upgrade”]

When I build the dockerfile it gives below error
RUN [“apt-get”,“update”,“&&”,“apt-get”,“upgrade”]:

/bin/sh: 1: Syntax error: Unterminated quoted string
ERROR: failed to solve: process “/bin/sh -c ["apt-get,"update","&&","apt-get","upgrade"]” did not complete successfully: exit code: 2

Also for RUN [“apt-get install apache2”]
It gives below error
runc run failed: unable to start container process: exec: “apt-get install apache2”: executable file not found in $PATH

Then I change to CMD apt install apache2
Now it gives below error
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: “apt-get install apache2”: executable file not found in $PATH: unknown.

Please advise!

You can read about shell form and exec form of RUN and CMD from the Dockerfile reference:

CMD and RUN are totally different instructions. RUN is for defining the commands that have to run during the build process to create an image and CMD is to define which command should be executed when you finally start the container from the existing image. Whether you need shell form or exec form for CMD varies depending on the command, but generally you should use the CMD instruction with the exec form:

CMD ["/path/to/your/command", "arg1", "arg2"]

which means the command will not run in a shell so stop signals can be handled by the command itself
and use the RUN instruction with the shell form which means that the commands will run in a shell which is required if you want pipes and execute multiple commands:

RUN apt-get update && apt-get upgrade
1 Like