我是Docker的新手,在使用以下RUN命令创建符号链接时遇到问题:
FROM php:7.3-apache
RUN ["/bin/bash", "-c", "ln -s /app/frontend/web/* /var/www/html"]
这是在容器内执行“ ls -la / var / www / html”时的输出:
'*' -> '/app/frontend/web/*'
我期待以下输出:
css -> /app/frontend/web/css
index.php -> /app/frontend/web/index.php
直接在容器中创建符号链接时,我得到了正确的输出,但是由于某些原因,在构建图像时,通配符(*)不起作用。
如果我将通配符替换为特定文件,则符号链接将在构建时正确创建。这是可行的,但我想避免列出文件夹中的每个文件:
FROM php:7.3-apache
RUN ["/bin/bash", "-c", "ln -s /app/frontend/web/index.php /var/www/html"]
任何人都知道如何执行此操作,我已经搜索了一段时间,并尝试了该RUN命令的不同语法,但没有成功。
谢谢
[*
与任何文件都不匹配时,它照原样传递给您的命令:
$ ls -l
total 0
-rw-r--r-- 1 leodag leodag 0 jun 17 03:29 a
-rw-r--r-- 1 leodag leodag 0 jun 17 03:29 b
-rw-r--r-- 1 leodag leodag 0 jun 17 03:29 c
$ ls d*
ls: cannot access 'd*': No such file or directory
所以您的问题是/app/frontend/web/
里面什么都没有,因为您还没有复制文件-您正试图在FROM
之后立即运行它。首先,您需要复制文件,以便全局匹配您的文件。否则,将glob表达式直接传递给ln
,创建一个名为*
的文件,指向不存在的*
文件。
FROM php:7.3-apache
COPY myfrontend/ /app/frontend/
RUN ["/bin/bash", "-c", "ln -s /app/frontend/web/* /var/www/html"]