Docker - RUN vs ENTRYPOINT vs CMD
RUN - Specify commands to make changes to your
Image and subsequently the Containers started from this Image. This includes
updating packages, installing software, adding users, creating an initial
database, setting up certificates, etc. These are the commands you would run at
the command line to install and configure your application.
Let's start with a basic dockerfile, where we are building an image with ubuntu as base image.
I am going to install packages like "curl", "wget" on the base image.
Now, the image size has increased from 78MB to 136MB. RUN command add another layer to the base image.
RUN is primarily used for software installation and any configuration changes.
ENTRYPOINT - Must be used if you want to start or a define a container main application or command. It always runs regardless of an additional CMD parameters.
This image is build using base "alpine" with entry point "ls". So, when the container starts it list files and folders.
Can we pass argument to ENTRYPOINT? YES
Arguments can be passed when creating container $ docker run <image> <parameter>
#
SSSame argument can passed via CMD parameter.
CMD - It does the same as ENTRYPOINT, but it can be overridden with the argument.
WWhen we use both, CMD is passed as an argument to ENTRYPOINT. So, this is what gets executed when the container starts # ls -lrt ls
sd
Another example.
A
S
I
Comments
Post a Comment