mv命令在dockerfile和本地linux中的行为方式的差异

Rus*_*kov 1 bash ubuntu docker wildfly dockerfile

我正在查看以下具有以下命令的jboss / wildfly docker 文件

mv $HOME/wildfly-$WILDFLY_VERSION $JBOSS_HOME
Run Code Online (Sandbox Code Playgroud)

其中$WILDFLY_VERSION=17.0.1.Final$JBOSS_HOME=/opt/jboss/wildfly.因此结果命令转换为:

mv $HOME/wildfly-17.0.1.Final /opt/jboss/wildfly
Run Code Online (Sandbox Code Playgroud)

在文件的后面,我们以如下方式启动wildfly:

CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0"]
Run Code Online (Sandbox Code Playgroud)

因此,我假设mv上面的命令将$HOME/wildfly-17.0.1.Final目录的内容 放入/opt/jboss/wildfly目录中。

但是,如果我尝试在本地计算机(ubuntu 18.04)上从dockerfile重新创建步骤,则会mv $HOME/wildfly-17.0.1.Final /opt/jboss/wildfly得到以下目录结构/opt/jboss/wildfly/wildfly-17.0.1.Final。也就是说,wildfly-17.0.1.Final目录本身被复制到中/opt/jboss/wildfly,而不是其内容中。有人可以解释一下为什么我在本地得到这个结果吗?

M03*_*M03 5

$JBOSS_HOME 路径不存在。

What the mv command does is actually replace the non-existent directory with the $HOME/wildfly-17.0.1.Final folder. That been said, the content of $HOME/wildfly-17.0.1.Final/ will be moved into $JBOSS_HOME replacing the name of the folder from "wildfly-17.0.1.Final" into "wildfly".

Simple Example would be as follow:

Create an empty dir and touch a file inside it, then try to do:

mv dir /var/lib/non_existing_folder
Run Code Online (Sandbox Code Playgroud)

dir will be moved as is and replace "non_existing_folder".