====== LU02a - Unterschied ENTRYPOINT vs CMD ======
====== LU02a - Unterschied ENTRYPOINT vs CMD ======
-
==== Ziele ====
+
===== Ziele =====
-
-Ich kann die Kommandos __ENTRYPOINT__ und __CMD__ beschreiben.
+
-Ich kann die Kommandos ''ENTRYPOINT'' und ''CMD'' beschreiben.
-
-Ich kann die unterschiedliche Anwendung von __ENTRYPOINT__ und __CMD__ beschreiben.
+
-Ich kann die unterschiedliche Anwendung von ''ENTRYPOINT'' und ''CMD'' beschreiben.
-
-Ich kann __ENTRYPOINT__ und __CMD__ in einem Docker-Datei gezielt anwenden.
+
-Ich kann ''ENTRYPOINT'' und ''CMD'' in einem Docker-Datei gezielt anwenden.
-Ich kann mindestens eine Massnahme bei Fehler im Build- oder Run-Prozess vorschlagen und umsetzen.
-Ich kann mindestens eine Massnahme bei Fehler im Build- oder Run-Prozess vorschlagen und umsetzen.
\\
\\
-
===== How to Use Docker EntryPoint =====
===== How to Use Docker EntryPoint =====
Zeile 20:
Zeile 19:
+
\\
==== How does docker ENTRYPOINT work? ====
==== How does docker ENTRYPOINT work? ====
-
When you specify command line arguments to the docker run command through ''exec form'', these arguments are appended to the end of all elements of the exec form, so the specified commands will <mark>run after the executables</mark> mentioned in entrypoint. For example, if you pass the '-d' argument to the 'docker run' command, the Docker will consider these arguments as the arguments of entrypoint and will execute them in the background. By doing this, you can turn your container into an executable. You can even add additional arguments to the entrypoint to convert a complex command line tool into a single argument docker container. The exec form just runs the binary you provide with the arguments you include but without any features of the shell parsing.
+
When you specify command line arguments to the docker run command through ''exec form'', these arguments are appended to the end of all elements of the exec form, so the specified commands will __run after the executables__ mentioned in entrypoint. For example, if you pass the '-d' argument to the 'docker run' command, the Docker will consider these arguments as the arguments of entrypoint and will execute them in the background. By doing this, you can turn your container into an executable. You can even add additional arguments to the entrypoint to convert a complex command line tool into a single argument docker container. The exec form just runs the binary you provide with the arguments you include but without any features of the shell parsing.
The ''shell form'' will execute the shell parameters as parameters to ''/bin/sh –c''. That allows you to expand variables, piping output, subcommands, chaining commands together, and other shell features. You cannot use shell form to specify any command or the docker run command-line arguments while starting the container because the ''ENTRYPOINT'' command runs as a subcommand of /bin/sh –c. The executable has a different process ID than the container's 'PID 1'. If we pass any Unix signals like SIGTERM from the docker stop command, the executable will receive it.
The ''shell form'' will execute the shell parameters as parameters to ''/bin/sh –c''. That allows you to expand variables, piping output, subcommands, chaining commands together, and other shell features. You cannot use shell form to specify any command or the docker run command-line arguments while starting the container because the ''ENTRYPOINT'' command runs as a subcommand of /bin/sh –c. The executable has a different process ID than the container's 'PID 1'. If we pass any Unix signals like SIGTERM from the docker stop command, the executable will receive it.
Zeile 58:
Zeile 58:
docker run testentrypoint
docker run testentrypoint
</code>
</code>
+
\\
==== Difference between ''ENTRYPOINT'' and ''CMD'' ====
==== Difference between ''ENTRYPOINT'' and ''CMD'' ====
Before we discuss the differences, let's look at some of the similarities between these two:
Before we discuss the differences, let's look at some of the similarities between these two:
Zeile 121:
Zeile 121:
Note that when ''ENTRYPOINT'' and ''CMD'' are both used in the same Dockerfile, everything specified in the ''CMD'' will be appended to the ''ENTRYPOINT'' as an argument.
Note that when ''ENTRYPOINT'' and ''CMD'' are both used in the same Dockerfile, everything specified in the ''CMD'' will be appended to the ''ENTRYPOINT'' as an argument.
+
\\
==== When to use docker ENTRYPOINT vs CMD ====
==== When to use docker ENTRYPOINT vs CMD ====
''ENTRYPOINT'' instructions can be used for both single-purpose and multi-mode docker images where you want a specific command to run upon the container start. You can also use it to build wrapper container images that encapsulate legacy programs for containerization, ensuring that the program will always run.
''ENTRYPOINT'' instructions can be used for both single-purpose and multi-mode docker images where you want a specific command to run upon the container start. You can also use it to build wrapper container images that encapsulate legacy programs for containerization, ensuring that the program will always run.