我有一个托管 Symfony Web 应用程序的 php 容器。我需要使用后台脚本并从 crontab 启动它们。而且只要我使用 root 用户,它似乎就可以工作。但是,当我将用户切换到“www-data”时 - 它停止工作。我的想法是以用户 www-data 身份运行 php-fpm,并在进入容器时登录“www-data”。但是 crontab 可以为 root 用户定义,因为它允许在命令前加上用户名。
我的入口点文件包含:
#!/bin/bash
npm install
cron &
php-fpm
Run Code Online (Sandbox Code Playgroud)
我的 docker 文件如下所示:
WORKDIR /app
ADD ./entrypoint.sh /entrypoint.sh
RUN chmod 777 /entrypoint.sh
ADD ./crontab.txt /etc/cron.d/hello-cron
RUN chmod 0666 /etc/cron.d/hello-cron
RUN crontab /etc/cron.d/hello-cron
RUN touch /var/log/cron.log
RUN usermod -s /bin/bash www-data
USER www-data
ENTRYPOINT /entrypoint.sh
Run Code Online (Sandbox Code Playgroud)
如果我跳过行,上面的方法就有效
USER www-data
Run Code Online (Sandbox Code Playgroud)
但我想首先启动 cron (针对 root),然后将默认容器用户切换到 www-data...所以我也尝试过:
ENTRYPOINT /entrypoint.sh
USER www-data
Run Code Online (Sandbox Code Playgroud)
但效果不太好。任何帮助将不胜感激 :)
我想递归地迭代结构定义,并为切片获取单一元素的类型。然后,创建该类型的空实例。例如:
type Path struct {
Name string
Points []Coordinate
}
type Coordinate struct {
Latitude float64
Longitude float64
}
Run Code Online (Sandbox Code Playgroud)
假设类型在运行时未知,我如何创建嵌套类型的空实例(在上面的示例中坐标)。我是说:
x := Coordinate{}
当输入时我得到 Path (可以是任何其他结构,具有不同类型的切片)?