Search code examples
dockerapt-getluarocks

Docker CMD instruction execution


My docker file has the following instructions

CMD ["luarocks","install",luasocket"]

When I try to build image, it builds successfully but luasocket is not installed yet all on my docker.
But when I execute this statement manually after "sudo apt-get update" on docker everything is going smooth.

Why it is being executed properly after "update" manually on command line. Even though my docker contains "update" command, why is it failing in this case?


Solution

  • But when I execute this statement manually after "sudo apt-get update" on docker every thing is going smooth

    If you execute a sudo apt-get update in a container session (ie., after a docker run), anything done by the apt-get command will be reset on the next docker run (next container).

    Make sure to include a RUN apt-get update in your Dockerfile if the command luarocks install luasocket needs it to complete sucessfully.

    More generally, this install command (luarocks install luasocket) should not be a CMD, but a RUN directive in order to bake into the image the installation of luasocket.