如何在dockerfile中编写长命令?

问题描述 投票:2回答:1

我想使用RUN指令在Dockerfile中编写以下命令:

cat > /etc/myconfig.conf << EOL  
line 1, ${kernel}  
line 2,  
line 3, ${distro}  
line 4  
line 5   
EOL  

我是按照以下方式做的,但似乎错了

RUN cat > /etc/myconfig.conf << EOL  \    
line 1, ${kernel}  \  
line 2,  \  
line 3, ${distro}  \  
line 4  \  
line 5   \  
EOL \  
docker dockerfile docker-compose docker-registry dockerhub
1个回答
0
投票

如果你想直接从Dockerfile运行它(没有额外的脚本),你也可以echo它并逃避换行符:

printf "line 1, ${kernel}\n line 2,\n line 3, ${distro}\n line 4\n line 5" >> /etc/myconfig.conf

但要小心:在Windows系统上,你需要一个\r\n

© www.soinside.com 2019 - 2024. All rights reserved.