Docker 高山 linux 运行 2 个程序

Docker Alpine linux running 2 programs

我正在尝试使用 alpine linux 创建 docker 图像,在 运行 之后将创建包含 2 个 运行ning 程序的容器。这 2(在我看来 - 我不太了解 docker)不能分开,因为第一个程序更改了秒配置文件,然后也应该重新启动该程序。

我正在努力如何 运行 这两个程序。我已经添加了自己的脚本,它应该 运行 该程序,但我遗漏了一些东西 - 脚本是每行 2 行是 运行 宁该程序的命令 - 它只启动第一个程序。

在 ubuntu 中使用 python 子进程和 systemctl 命令我重新启动 运行ning 服务但是在高山 linux 它是 运行ning 作为程序,我不知道如何 restart/reload 它。

您需要 运行 后台第一个程序才能执行脚本的第二行。

每当你有两个进程必须 运行 在一个容器中时,就会存在 的风险(即容器不会将 SIGKILL 信号正确传递给 all 个进程)。
用作您的基础映像 phusion/baseimage-docker:它是为管理多个进程而设计的。

我建议看看 supervisord approach. You can find how to use it in docker documentation

一些例子:

1. Dockerfile 是:

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 是:

[supervisord]
nodaemon=true

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

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