Docker Alpine linux running 2 programs

夙愿已清 提交于 2019-12-29 07:11:58

问题


I am trying to create docker image with alpine linux, which after run will create container with 2 running programs. This 2 (in my opinion - I don't know docker well) can't be separated because first program changes the seconds configuration file and then should restart that program too.

I am struggling how to run both programs. I have added own script which should run that programs but I am missing something - script is 2 lines on each line is command for running that program - and it only starts first program.

In ubuntu with python subprocess and systemctl command I restart running service but in alpine linux it's running as program and I don't know how to restart/reload it.

Thanks for every help


回答1:


I would suggest to look at supervisord approach. You can find how to use it in docker documentation.

Some example:

1. Dockerfile is:

FROM alpine:latest
RUN apk update && apk add --no-cache supervisor openssh nginx
COPY supervisord.conf /etc/supervisord.conf
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]

2. supervisord.conf is:

[supervisord]
nodaemon=true

[program:sshd]
command=/usr/sbin/sshd -D

[program:nginx]
command=nginx -c /etc/nginx/nginx.conf



回答2:


You would need to run the first program in background for the second line of your script to execute.

Whenever you have two processes which must run inside one container, there is the risk of zombie processes (ie the container won't pass correctly the SIGKILL signal to all processes).
Use as your base image phusion/baseimage-docker: it is made for managing multiple processes.



来源:https://stackoverflow.com/questions/49090469/docker-alpine-linux-running-2-programs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!