$ docker run --p :-v $()/logs/nginx:/var/log/--restart=--name=.
#!/bin/<span style="color: #0000ff">for ((i=<span style="color: #800080">1;i<=<span style="color: #800080">100000;i++<span style="color: #000000">))
<span style="color: #0000ff">do<span style="color: #000000">
curl http:<span style="color: #008000">//<span style="color: #008000">localhost > /dev/null
<span style="color: #0000ff">sleep <span style="color: #800080">1
<span style="color: #0000ff">done
<span style="color: #0000ff">do<span style="color: #000000">
curl http:<span style="color: #008000">//<span style="color: #008000">localhost > /dev/null
<span style="color: #0000ff">sleep <span style="color: #800080">1
<span style="color: #0000ff">done
#!/bin/getdatestring()
{
TZ=<span style="color: #800000">'<span style="color: #800000">Asia/Chongqing<span style="color: #800000">' <span style="color: #0000ff">date <span style="color: #800000">"<span style="color: #800000">+%Y%m%d%H%M<span style="color: #800000">"<span style="color: #000000">
}
datestring=<span style="color: #000000">$(getdatestring)
{
TZ=<span style="color: #800000">'<span style="color: #800000">Asia/Chongqing<span style="color: #800000">' <span style="color: #0000ff">date <span style="color: #800000">"<span style="color: #800000">+%Y%m%d%H%M<span style="color: #800000">"<span style="color: #000000">
}
datestring=<span style="color: #000000">$(getdatestring)
<span style="color: #0000ff">mv /var/log/nginx/access.log /var/log/nginx/<span style="color: #000000">access.${datestring}.log
<span style="color: #0000ff">mv /var/log/nginx/error.log /var/log/nginx/<span style="color: #000000">error.${datestring}.log
<span style="color: #0000ff">kill -USR1 <span style="color: #0000ff">cat</span> /var/run/nginx.pid
$ +x rotatelog. rotatelog. $()/logs/nginx
$ docker exec mynginx bash /var/log/nginx/rotatelog.
* * * * docker exec mynginx bash /var/log/nginx/rotatelog.
》一文中介绍了容器中信号的捕获问题,感兴趣的朋友可以去看看。在那篇文章中我们介绍了 docker 向容器中进程发送信号的 kill 命令。我们可以通过命令:
$ docker container mynginx -s USR1