Dockerfile里pip.conf报错ConfigParser.MissingSectionHeaderError: File contains no section headers.

Dockerfile的部分内容如下:

RUN mkdir /root/.pip && echo -e "[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple" > /root/.pip/pip.conf
RUN pip install PyCryptodome

目测是没有问题,可是docker build的时候就报错:

ConfigParser.MissingSectionHeaderError: File contains no section headers.

惊讶,然后尝试打印pip.conf的内容:

-e [global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

发现-e竟然进入到文件内容里,诡异。

最后发现去掉-e就可以,而且Dockerfile的echo不加-e参数也可以识别转义字符。

原文地址:https://www.cnblogs.com/pcat/p/12573332.html