繁体   English   中英

在单个 docker 容器中启动 cron 和另一个进程

[英]Start cron and another process in single docker container

我有一个 docker 图像,它将启动一个前台 httpd 进程。 我还有一些我想通过 crontab 作为 cron 作业运行的任务。

理想情况下,我想以非 root 用户身份启动 httpd,但是,要启动 cron,我需要成为 root

FROM ubuntu:latest

RUN apt-get update 
    && DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -yq \
    && apt-get install -y cron httpd

# Do a bunch of other setup.....

USER 1000

#START PROCESSES....

我看到的问题是我无法以 root 身份启动 cron,保持该进程运行,也无法将 httpd 作为前台进程启动。

有没有办法让这两个进程在一个 docker 容器中启动?

您可以配置用于在 docker 中运行命令的用户,例如

ENV     USER_NAME dev                                                       
RUN     echo "${USER_NAME} ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/${USER_NAME} && \
        chmod 0440 /etc/sudoers.d/${USER_NAME}

ARG     host_uid=1001                                                               
ARG     host_gid=1001                                                               
RUN     groupadd -g $host_gid $USER_NAME && useradd -g $host_gid -m -s /bin/bash -u $host_uid $USER_NAME

并使用构建您的图像

docker build --build-arg "host_uid=$(id -u)" --build-arg "host_gid=$(id -g)" -t <ur img> .

但是为什么不能每次都运行一个 bash 脚本在后台执行进程呢?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM