'Docker override ENTRYPOINT but keep CMD
I need to extend a base image (jwilder/nginx-proxy) because I need to add some additional configuration to that image.
Some of these configuration changes need to be done during the container's runtime, before the logic of the base image starts.
The way that I have implemented that runtime configuration is by creating a custom ENTRYPOINT file that first does all my custom work and then starts the base image's entrypoint.
My entrypoint looks like this:
#!/bin/bash
# my custom logic here
echo "Executed custom logic."
# default jwilder/nginx entrypoint
/app/docker-entrypoint.sh "$@"
Currently, this does not work because "$@" resolves to nothing. My custom Dockerfile does not set a custom CMD, only the ENTRYPOINT.
Is there a reason why this does not work? I would have hoped that the base images's CMD remains set and is passed to my ENTRYPOINT. Otherwise I need to copy the base image's CMD which is prone to errors if that CMD ever changes.
Solution 1:[1]
From the docs
If CMD is defined from the base image, setting ENTRYPOINT will reset CMD to an empty value. In this scenario, CMD must be defined in the current image to have a value.
This goes for CMD as well. CMD and ENTRYPOINT resets any CMD or ENTRYPOINT values from the base image.
You have to set it yourself again.
If you're concerned about the value changing - and the base image is under your control - you could set an environment variable instead and use that.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hans Kilian |
