docs: rewrite section on default entrypoint

Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
This commit is contained in:
David Karlsson 2023-11-27 11:24:42 +01:00
parent c695ad9d74
commit b01e287527
1 changed files with 22 additions and 16 deletions

View File

@ -924,27 +924,33 @@ get appended as arguments to the `ENTRYPOINT`.
### Default entrypoint ### Default entrypoint
```console ```text
--entrypoint="": Overwrite the default entrypoint set by the image --entrypoint="": Overwrite the default entrypoint set by the image
``` ```
The `ENTRYPOINT` of an image is similar to a `COMMAND` because it The entrypoint refers to the default executable that's invoked when you run a
specifies what executable to run when the container starts, but it is container. A container's entrypoint is defined using the Dockerfile
(purposely) more difficult to override. The `ENTRYPOINT` gives a `ENTRYPOINT` instruction. It's similar to specifying a default command because
container its default nature or behavior, so that when you set an it specifies, but the difference is that you need to pass an explicit flag to
`ENTRYPOINT` you can run the container *as if it were that binary*, override the entrypoint, whereas you can override default commands with
complete with default options, and you can pass in more options via the positional arguments. The defines a container's default behavior, with the idea
`COMMAND`. But, sometimes an operator may want to run something else that when you set an entrypoint you can run the container *as if it were that
inside the container, so you can override the default `ENTRYPOINT` at binary*, complete with default options, and you can pass in more options as
runtime by using a string to specify the new `ENTRYPOINT`. Here is an commands. But there are cases where you may want to run something else inside
example of how to run a shell in a container that has been set up to the container. This is when overriding the default entrypoint at runtime comes
automatically run something else (like `/usr/bin/redis-server`): in handy, using the `--entrypoint` flag for the `docker run` command.
The `--entrypoint` flag expects a string value, representing the name or path
of the binary that you want to invoke when the container starts. The following
example shows you how to run a Bash shell in a container that has been set up
to automatically run some other binary (like `/usr/bin/redis-server`):
```console ```console
$ docker run -it --entrypoint /bin/bash example/redis $ docker run -it --entrypoint /bin/bash example/redis
``` ```
or two examples of how to pass more parameters to that ENTRYPOINT: The following examples show how to pass additional parameters to the custom
entrypoint, using the positional command arguments:
```console ```console
$ docker run -it --entrypoint /bin/bash example/redis -c ls -l $ docker run -it --entrypoint /bin/bash example/redis -c ls -l
@ -959,8 +965,8 @@ $ docker run -it --entrypoint="" mysql bash
> **Note** > **Note**
> >
> Passing `--entrypoint` will clear out any default command set on the > Passing `--entrypoint` clears out any default command set on the image. That
> image (i.e. any `CMD` instruction in the Dockerfile used to build it). > is, any `CMD` instruction in the Dockerfile used to build it.
### Exposed ports ### Exposed ports