【发布时间】:2019-04-05 19:34:35
【问题描述】:
我正在使用下面的Dockerfile 和entrypoint.sh。我需要以非 root 用户身份在容器中启动 crond 服务,但我得到了 Permission denied。如何以非 root 用户身份启动crond 服务?
我需要在 Dockerfile 中添加 USER,因为这是我的 Openshift 3 平台中的强制性管理设置。
Dockerfile
FROM centos:centos7.4.1708
RUN yum update -y && yum install -y cronie && rm -rf /var/lib/apt/lists/*
RUN cd / && mkdir /code
ADD entrypoint.sh /code/
RUN chmod -R 755 /code/entrypoint.sh
ENTRYPOINT ["/code/entrypoint.sh"]
RUN useradd -l -u 1001510000 -c "1001510000" 1001510000
USER 1001510000
CMD ["top"]
entrypoint.sh
#!/bin/bash
echo "in the entrypoint!"
echo "executing id"
id
echo "executing crond start"
crond start
echo "executing $@"
$@
错误输出
in the entrypoint!
executing id
uid=1001510000(1001510000) gid=1000(1001510000) groups=1000(1001510000)
executing crond start
crond: can't open or create /var/run/crond.pid: Permission denied
executing top
【问题讨论】: