简体   繁体   中英

Docker AutoStartup service NGINX

I want to AutoStartup Service NGINX in Docker Containers,

I tried adding this code in DOCKERFILE FILE, but the service doesn't auto start.

RUN service nginx start
CMD service nginx start

Issue is that this service/Daemon is going to run in background.

Go through following article for more information How to Run a Daemon Service in the Foreground

Quick workaround is to replace CMD or ENTRYPOINT with You must figure out the start command in order to run in the foreground.

(Note: Daemon Service = Binary + Configuration + Initscript.)

To run the process in the foreground, we just need these two ingredients:

Binary: bash -x /etc/init.d/XXX start.
Here, -x instructs shell to display verbose output. Should be easy to figure out binary path. Another trick is _”ps -ef | grep $PROCESS_PATTERN”_.
Configuration: Typically speaking, we can dig out from console output of bash -x. Sometimes, it’s just too long to read. Figure out the process ID and the list environment from cat /proc/$pid/environ.
A lot of decent services refuse to run as root because of security concerns. Here is how to impersonate other users with root.

So in your case executable command should be

CMD ["bash", "-x", "/etc/init.d/nginx","start"]

Or tweek it accordingly.
In case you need more help ,let me know in comments section.

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