build立Arch Linux的Docker映像挂起 – 运行pacman -Syyu – 需要–noconfirm

我正在尝试使用Dockerfile构build自定义Docker镜像。 我正在使用的基本映像是这样的:

l3iggs / ArchLinux的

我的Dockerfile是这样的:

FROM l3iggs/archlinux:latest COPY source /srv/visitor WORKDIR /srv/visitor RUN pacman -Syyu --needed --noconfirm && pacman -S --needed --noconfirm cronie nodejs phantomjs && printf "1.2.3.4 www.hahaha.org \n" >> /etc/hosts && printf "*/2 * * * * node /srv/visitor/visitor.js \n" >> cronJobs && printf "*/5 * * * * killall -older-than 5m phantomjs \n" >> cronJobs && printf "0 0 * * * rm /srv/visitor/visitor-info.log \n" >> cronJobs && crontab cronJobs && rm cronJobs && npm install EXPOSE 80 CMD ["/bin/sh", "-c"] 

现在,当它到达应该更新的“RUN”部分时,它会挂起并输出以下错误消息:

 Step 3 : RUN pacman -Syyu --needed --noconfirm && ---> Running in ae19ff7ca233 /bin/sh: -c: line 1: syntax error: unexpected end of file INFO[0013] The command [/bin/sh -c pacman -Syyu --needed --noconfirm &&] returned a non-zero code: 1 

有任何想法吗?

更新1:

现在,我怀疑我的问题与“RUN”命令有关,而不是在容器内部执行“pacman -Syyu”。 这应该真的不是刹车的事情,但显然是。

您缺less\用于跨多行构build您的命令。 运行命令应该看起来更像是:

 RUN pacman -Syyu --needed --noconfirm && \ pacman -S --needed --noconfirm cronie nodejs phantomjs && \ printf "1.2.3.4 www.hahaha.org \n" >> /etc/hosts && \ printf "*/2 * * * * node /srv/visitor/visitor.js \n" >> cronJobs && \ printf "*/5 * * * * killall -older-than 5m phantomjs \n" >> cronJobs && \ printf "0 0 * * * rm /srv/visitor/visitor-info.log \n" >> cronJobs && \ crontab cronJobs && \ rm cronJobs && \ npm install 

虽然,有几件事要注意:

  • 在构build过程中,您正在运行crontab作为命令。 当您运行实际的图像时,这将不会运行。
  • 您在构build期间添加主机条目。 这可能会在运行时被覆盖。 这里有一个--add-host运行时选项: https : //docs.docker.com/reference/commandline/cli/#adding-entries-to-a-container-hosts-file 。
  • 您不需要将命令设置为/bin/sh -c 。 Docker实际上为你做了这个,如果你只是传递一个裸露的命令在数组之外。 请参阅https://docs.docker.com/reference/builder/#cmd上的三个CMD表单的最后一个。