Wordpress: Variable Unbound Error: When adding a custom entrypoint that uses the original docker-entrypoint.sh

Created on 5 Jan 2017  路  5Comments  路  Source: docker-library/wordpress

Official Wordpress "docker-entrypoint.sh" is run from a custom shell script, throughs an error:
/usr/local/bin/docker-entrypoint.sh: line 26: $1: unbound variable
Line points to:
if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then in https://github.com/docker-library/wordpress/blob/master/docker-entrypoint.sh

Steps to reproduce:

  • Add a custom entrypoint to docker-compose.yml (after adding the file to container /usr/local/bin/custom-entrypoint.sh using the Dockerfile):
    ... entrypoint: custom-entrypoint.sh
    Contents of custom-entrypoint.sh:
sed -i -e 's/^exec "$@"/#exec "$@"/g' /usr/local/bin/docker-entrypoint.sh
source docker-entrypoint.sh
exec "$@"
  • Build & Run the error will appear, although it is the exact same shell from the official repository, what's different ?

Most helpful comment

Just some background info for others who find this thread:
The basic problem is that if the base image defines BOTH CMD and ENTRYPOINT, your image also has to override both. You can't just override ENTRYPOINT and then keep/inherit CMD. The docs say:

Note: 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.

Source: https://docs.docker.com/engine/reference/builder/#entrypoint

All 5 comments

What's different is the arguments provided -- in the image as-is, we don't run docker-entrypoint.sh by itself, but rather pass apache2-foreground or php-fpm to it (depending on which variant we're using). So the final command is something more like docker-entrypoint.sh apache2-foreground.

That what I was missing... Thanks ! I ended up forking the dockerfile and related docker-entrypoint.sh, and added what I need.
Can you explain to me in simple words what this gibberish means:
sed -i -e 's/^exec "$@"/#exec "$@"/g' /usr/local/bin/docker-entrypoint.sh although I'm no longer using it, had a hard time understanding it. Where does it search for exec in ? what does it replace ? Why ?

That line searches for a line that starts with exec "$@" in the existing entrypoint script and comments it out so that it doesn't run. That exec line will actually _run_ the arguments to the script after it executes, rather than simply running the initialization steps.

Oh.. simple way of extending the shell script. Thanks

Just some background info for others who find this thread:
The basic problem is that if the base image defines BOTH CMD and ENTRYPOINT, your image also has to override both. You can't just override ENTRYPOINT and then keep/inherit CMD. The docs say:

Note: 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.

Source: https://docs.docker.com/engine/reference/builder/#entrypoint

Was this page helpful?
0 / 5 - 0 ratings

Related issues

etc0de picture etc0de  路  4Comments

ptrdlbrg picture ptrdlbrg  路  5Comments

tnguyen14 picture tnguyen14  路  3Comments

chrissound picture chrissound  路  5Comments

haszari picture haszari  路  4Comments