本文介绍了重定向Docker中Nohup的输出不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在docker中运行flask应用程序.当我运行start.sh(以下详细信息)时启动了应用程序,该操作使用nohup命令启动了应用程序,并将输出重定向到日志文件.

I have to run a flask application in docker. The application is started when I run start.sh (details below) which started the application using nohup command and redirects the output to a logfile.

这在正常的Linux系统(没有docker)中运行良好,但是当我在docker容器中运行该文件时,日志文件未显示任何输出.在docker容器中,将生成大小为0的日志文件,并将日志输出转储到nohup.out文件中.

This is running fine in normal Linux system (without docker), but when I run this inside a docker container, the log file does not show any output. In the docker container, the log file is generated with size 0 and the log output is dumped in nohup.out file.

我不确定为什么将输出重定向到nohup.out而不是指定的日志文件,尽管在我当前的Linux设置中它可以正常工作.

I am not sure why the output is redirected to nohup.out instead of the specified logfile, while it is working fine in my current Linux setup.

start.sh:

nohup uwsgi --ini /home/myuser/myapp/play.ini &>> /home/myuser/myapp/logs/play.nohup.out &

Dockerfile:

Dockerfile:

#Download base image ubuntu 16.04
FROM ubuntu:16.04

RUN apt-get update
RUN apt-get install -y git-core
RUN apt-get install -y nginx
RUN apt-get install -y python

# get application code and install python packages
RUN git clone <..git directory...> /home/myuser/myapp
RUN pip install -r /home/myuser/myapp/requirements.txt

# Setup nginx
RUN cp /home/myuser/myapp/myapp.conf /etc/nginx/conf.d/myapp.conf

CMD sleep 600
EXPOSE 80

推荐答案

我在使用cron命令时遇到了类似的问题,我发现的问题是该命令是与Shell一起运行的,但 shell 不支持&>> ,因为它是 bash 功能.

I faced similar issue using cron commands, the issue I found is that the command was ran with shell, but shell does not support &>> as it is a bash feature.

我能够使用带有以下synthax的命令来克服这一问题:

I was able to overcome that using a command with the following synthax:

command >> logfile.log 2>&1

您可以在此链接 https://www中找到更多信息.brianstorti.com/understanding-shell-script-idiom-redirect/

这篇关于重定向Docker中Nohup的输出不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 08:18