After the execution of my entrypoint script the containers stops with Exit 0. The command specified in the compose file which is starting our webserver is ignored.
We are using docker with docker-compose as environment for our rails applications.
The entrypoint script:
#! /bin/bash
bundle exec rails assets:clobber
bundle exec rails assets:precompile
bundle exec rake db:exists && bundle exec rake db:migrate || bundle exec rake db:setup
rm -rf /aps/tmp/pids/server.pid
The compose file:
version: '2'
services:
app:
image: registry.gitlab.com/.../.../master:latest
command: bundle exec rails server
entrypoint: /aps/rails-entrypoint.sh
volumes:
- /srv/app/log/:/app/log
- /srv/app/public/:/app/public
env_file: .env
ports:
- '0.0.0.0:3333:3000'
links:
- apppostgres
apppostgres:
image: postgres
...
volumes:
pgdata:
When I connect into the container while the entrypoint script is running I can see the executed command running with ps aux as /bin/bash /app/rails-entrypoint.sh bundle exec rails server.
When I add my command block to the entrypointscript the server is started and running but this is nor how it should work or?
What can I do to get the entrypoint script and command block running as they should?
When you start the container then the process which initiated the container - entrypoint.sh in your case - will be considered pid 1 so as long as this process is running your container stays up and running and if it dies or stopped for whatever reason it will stop the container with exit status 0 or higher depends on the actual exit status of the main process.
You need to add the following at the end of your entrypoint in order to make it work with bundle exec rails server
exec "$@"
After the execution of my entrypoint script the containers stops
This is pretty much definitional: when the entrypoint completes the container exits.
The command specified in the compose file which is starting our webserver is ignored.
It's passed as command-line arguments to the entrypoint, and it's up to your script to do whatever's appropriate with it.
The most common thing to do is to exec the command-line arguments unmodified:
#!/bin/sh
# ... do pre-launch setup ...
exec "$@"
(ENTRYPOINT and CMD do not combine on their own to let you run two things in order in a container: only the entrypoint is run, getting the command as parameters, and the lifetime of the container is exactly the lifetime of the entrypoint.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With