dockerfile 编写求助

这个 dockerfile 编译后,我进入容器内发现 /usr/local/bin/目录下,并没有 queue.tar.gz 和解压的文件
这是为什么?

FROM bitnami/php-fpm:7.3

ENV QUEUE_TOKEN="123" \
    QUEUE_HOST="http://disk.mcjy.top/Queue"
 
RUN  cd  /usr/local/bin/ && \
wget  -O queue.tar.gz  https://github.com/cloudreve/taskqueue/releases/download/1.1/taskqueue_1.1_linux_amd64.tar.gz && \
tar -zxvf  queue.tar.gz  && \
chmod +x ./taskqueue && \
sed -i '/api/'d  conf.yaml && \
sed -i '/token/'d conf.yaml && \
sed -i '1 i token: $QUEUE_TOKEN' conf.yaml&& \
sed -i '1 i api: $QUEUE_HOST' conf.yaml && \
./taskqueue >/temp/q.log &

CMD [ "php-fpm", "-F", "--pid", "/opt/bitnami/php/tmp/php-fpm.pid", "-y", "/opt/bitnami/php/etc/php-fpm.conf" ]
阅读 2.1k
1 个回答
RUN  cd  /usr/local/bin/ && \
wget  -O queue.tar.gz  https://github.com/cloudreve/taskqueue/releases/download/1.1/taskqueue_1.1_linux_amd64.tar.gz && \
tar -zxvf  queue.tar.gz  && \
chmod +x ./taskqueue && \
sed -i '/api/'d  conf.yaml && \
sed -i '/token/'d conf.yaml && \
sed -i '1 i token: $QUEUE_TOKEN' conf.yaml&& \
sed -i '1 i api: $QUEUE_HOST' conf.yaml && \
./taskqueue >/temp/q.log &

最后为什么要加一个 & 呢?

bash 执行的命令如果以 & 结束,那么会新建一个 subshell ,然后异步执行。当前 bash 命令立即返回成功。

If a command is terminated by the control operator ‘&’, the shell executes the command asynchronously in a subshell. This is known as executing the command in thebackground, and these are referred to asasynchronouscommands. The shell does not wait for the command to finish, and the return status is 0 (true).

而 dockerfile 执行,shell 返回成功就结束了,不会等 subshell 运行的。所以,subshell 里的命令应该是根本没有机会执行。

把最后的 & 去掉就好了。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题