EntryPoint¶
https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#entrypoint
example¶
docker-entrypoint.sh
docker entrypoint
change the docker-entrypoint file to update .condarc channel_alias¶
docker-entrypoint.sh
#!/bin/bash
set -e
# Update channel_alias setting in .condarc
if [ -n "$CONDA_CHANNEL_ALIAS" ]; then
conda config --set channel_alias "$CONDA_CHANNEL_ALIAS"
fi
exec "$@"
cmd vs entrypoint¶
The main difference between CMD and ENTRYPOINT in a Dockerfile lies in how they are used and overridden when running a container.
CMD¶
The
CMDinstruction in a Dockerfile specifies the default command to run when the container starts.If a Dockerfile has multiple
CMDinstructions, only the last one will take effect.The
CMDinstruction can be overridden when running the container by specifying a command at the end of thedocker runcommand. If no command is specified, theCMDinstruction from the Dockerfile is executed.If the Dockerfile specifies an
ENTRYPOINT, theCMDvalues are appended to theENTRYPOINTto form the command that is run.
Example:
When running a container from this image, if no command is specified, it will start nginx with the specified configuration. However, you can override theCMD by specifying a different command when running the container. ENTRYPOINT¶
The
ENTRYPOINTinstruction in a Dockerfile specifies the executable that will run when the container starts.If a Dockerfile has multiple
ENTRYPOINTinstructions, only the last one will take effect.The
ENTRYPOINTinstruction cannot be overridden likeCMD. Instead, any commands provided when running the container are passed as arguments to theENTRYPOINT.If the Dockerfile specifies both
ENTRYPOINTandCMD, theCMDvalues are passed as arguments to theENTRYPOINT.
Example:
In this case,nginx is the executable that will run when the container starts. Any additional arguments provided when running the container are appended to the ENTRYPOINT command. In summary, ENTRYPOINT sets the main command and CMD provides default arguments for that command. When both are used together, CMD values are passed as arguments to ENTRYPOINT.