在Dockerfile中使用多行命令处理EOF

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

我正在尝试使用sfdisk在docker容器内创建图像文件,我可以使用以下命令没有任何问题:

root@c8e9be2eb26f:/# sfdisk bbb_image.img << EOF
> 1M,48M,0xE,*
> ,,,-
> EOF
Checking that no-one is using this disk right now ... OK

Disk bbb_image.img: 1 GiB, 1073741824 bytes, 2097152 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

>>> Created a new DOS disklabel with disk identifier 0x34b8e793.
bbb_image.img1: Created a new partition 1 of type 'W95 FAT16 (LBA)' and of size 48 MiB.
bbb_image.img2: Created a new partition 2 of type 'Linux' and of size 975 MiB.
bbb_image.img3: Done.

New situation:
Disklabel type: dos
Disk identifier: 0x34b8e793

Device         Boot  Start     End Sectors  Size Id Type
bbb_image.img1 *      2048  100351   98304   48M  e W95 FAT16 (LBA)
bbb_image.img2      100352 2097151 1996800  975M 83 Linux

The partition table has been altered.
Syncing disks.

现在在我的Dockerfile中,这似乎不起作用,并且再现了不完整的结果:

RUN sfdisk bbb_image.img << "EOF\n\
1M,48M,0xE,*\n\
,,,-\n\
EOF"

并在控制台中重现此错误信息:

Step 4/4 : RUN sfdisk bbb_image.img << "EOF\n1M,48M,0xE,*\n,,,-\nEOF\n"
 ---> Running in afc86ffef92a
Checking that no-one is using this disk right now ... OK

Disk bbb_image.img: 1 GiB, 1073741824 bytes, 2097152 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

>>> Done.

New situation:
ERROR: Service 'test' failed to build: The command '/bin/sh -c sfdisk bbb_image.img << "EOF\n1M,48M,0xE,*\n,,,-\nEOF\n"' returned a non-zero code: 1

我不确定如何在Dockerfile中处理EOF。

linux docker dockerfile eof
1个回答
0
投票

也许可以试试这个:

RUN sfdisk bbb_image.img << "\n1M,48M,0xE,*\n,,,-\n"
© www.soinside.com 2019 - 2024. All rights reserved.