问题
我试图在Docker中使用python模块colorama (打印彩色消息),但不幸的是,它无法工作:
python3 main.py运行的工作原理是预期的。docker run -p 5000:5000 hello_docker:latest不会打印消息w/out颜色。项目
OS
Kernel Version: 4.19.81-Re4son-v8l+
Operating System: Kali GNU/Linux Rolling
OSType: linux
Architecture: aarch64树
./main.py
./__init__.py
./requirements.txt
./DockerfileDockerfile
# Dockerfile
FROM python:3.8
WORKDIR /srv
ADD ./requirements.txt /srv/requirements.txt
RUN pip install -r requirements.txt
ADD . /srv
CMD python /srv/main.pyrequirements.txt
coloramamain.py
from colorama import init, Fore, Style
if __name__ == '__main__':
init()
msg = Fore.GREEN + "Python 3.8 says hello in green from Docker !" + Style.RESET_ALL
print(msg, flush=True)发布于 2019-12-28 14:07:18
您可以激活-it标志
docker run -it -p 5000:5000 hello_docker:latest-it是--交互式+ --tty。这使我们能够直接查看容器内部的输出。
-t : Allocate a pseudo-tty
-i : Keep STDIN open even if not attachedhttps://stackoverflow.com/questions/59511580
复制相似问题