简体   繁体   中英

Docker is not running my entire entrypoint.sh script

I have created a docker container to stand up Elasticsearch. Elasticsearch is being started and managed by supervisor which is also installed on my docker container. I have created an entrypoint.sh script and added the following to the end of my Dockerfile

ENTRYPOINT ["/usr/local/startup/entrypoint.sh"]

My entrypoint.sh script looks as follows:

#!/bin/bash -x

# Start Supervisor if not already running
if ! ps aux | grep -q "[s]upervisor"; then
  echo "Starting supervisor service"
  exec/usr/bin/supervisord -nc /etc/supervisor/supervisord.conf

else
  echo "Supervisor is currently running"
fi

echo "creating /.es_created"
touch /.es_created

exec "$@"

When I start my docker container supervisor starts and in turn will successfully start elasticsearch. The problem is that it never executes the last bit of the script creating the .es_created file. It seems like once the

exec /usr/bin/supervisord -nc /etc/supervisor/supervisord.conf

command is executed, it just stops there. I added -x to the #!/bin/bash so I could call docker logs on the container and it confirms that it never calls the last echo and touch commands. I feel like I may be missing something about entrypoint scripts which is why this is happening, but ultimately I want to be able to execute some commands after elasticsearch has started so I can configure a proper index and insert some data.

Your guess

It seems like once the

 exec /usr/bin/supervisord -nc /etc/supervisor/supervisord.conf 

command is executed, it just stops there.

is correct, because the exec command of bash has indeed the following semantics: the specified program at stake is executed, and replace the parent shell process (it is an exec system call ).

So your question is actually not a Docker issue, it is rather related to Bash. For more details on the exec shell builtin, you could for example take a look at this askubuntu question , or read the corresponding doc in the bash reference manual .

To sum up, you should try to just write

/usr/bin/supervisord -nc /etc/supervisor/supervisord.conf

If that command indeed runs in the background, it should be OK. Otherwise, you could of course append a & :

/usr/bin/supervisord -nc /etc/supervisor/supervisord.conf &

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM