Reputation: 421
I have a Dockerfile set up to run a service that requires some subsequent commands be run in order to initialize properly. I have created a startup script with the following structure and set it as my entrypoint:
Obviously, this does not work since the service was started in background and the entry point script will exit with code 0. How can I keep this container running after the configuration has been done? Is it possible to do so without a busy loop running?
Upvotes: 0
Views: 1325
Reputation: 525
You can look at this GitHub issue and specific comment - https://github.com/docker-library/wordpress/issues/205#issuecomment-278319730
To summarize, you do something like this:
version: '2.1'
services:
db:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
image: wordpress:latest
volumes:
- "./wp-init.sh:/usr/local/bin/apache2-custom.sh"
depends_on:
db:
condition: service_started
ports:
- 80:80
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_PASSWORD: wordpress
command:
- apache2-custom.sh
wp-init.sh
is where you write the code to execute.
Note the command
yml tag:
command:
- apache2-custom.sh
because we bounded the two in the volumes
tag, it will actually run the code in wp-init.sh
within your container.
Upvotes: 0
Reputation: 311526
How can I keep this container running after the configuration has been done? Is it possible to do so without a busy loop running?
Among your many options:
sleep inf
, which is not a busy loop and does not consume CPU time.supervisord
to start your service and start the configuration script.Upvotes: 1