我正在Docker化一个应用程序,它涉及通过Clang将二进制文件与其他C文件相关联。我们维护了二进制文件的符号链接版本,因为它们在整个代码库中使用。我的Docker构建目录包含整个代码库(包括源文件以及这些源文件的符号链接),当我执行cat [symlinked_file]
之类的操作时,Docker会识别这些文件(即文件为cat
正确)。但是,当我在Makefile中运行我的Clang命令时,它无法链接符号链接的文件(这些工作在Docker中没有问题)。然后我将原件复制到符号链接所在的目录中,替换了符号链接,而Docker没有在构建时抛出任何错误。
有谁知道怎么解决这个问题?我需要在这里给Docker或Clang任何特殊命令吗?我不确定为什么Clang在Docker容器内的行为与其外部不同。我从Ubuntu 16.04 Base Image运行以供参考。
答案 0 :(得分:4)
Docker将使用符号链接(至少在我的linux主机上构建时),但符号链接目标需要在构建上下文中。此上下文被发送到docker引擎,并且构建发生在容器内的该服务器上,因此任何指向该上下文之外的文件的链接都将无法解析:
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
void square_plus1()
{
int fd[2];
int fd2[2];
int fd3[3];
int value;
int myInt;
int status;
pid_t child1;
pid_t child2;
pipe(fd);
pipe(fd2);
pipe(fd3);
child1 = fork();
child2 = fork();
if(child1 == 0)
{
close(fd3[0]);
close(fd3[1]);
close(fd[1]);
close(fd2[0]);
read(fd[0],&value,sizeof(value));
close(fd[0]);
printf("Child1(%d) received value: %d\n", getpid(), value);
value = value * value;
write(fd2[1],&value,sizeof(value));
close(fd2[1]);
exit(0);
}
else if(child2 == 0)
{
close(fd[0]);
close(fd[1]);
close(fd2[1]);
close(fd3[0]);
read(fd2[0],&value,sizeof(value));
printf("Child2(%d) received value: %d\n", getpid(), value);
close(fd2[0]);
value++;
write(fd3[1],&value,sizeof(value));
close(fd3[1]);
exit(0);
}
else
{
while((scanf("%d", &value)) != EOF)
{
write(fd[1],&value, sizeof(value));
printf("Parent(%d) sent value: %d\n", getpid(), value);
waitpid(child1,&status,0);
if(status == 0)
{
}
waitpid(child2,&status,0);
if(status == 0)
{
}
read(fd3[0],&value,sizeof(value));
printf("New Value: %d\n",value);
}
waitpid(child1,&status,0);
if(status == 0)
{
printf("Child 1 finishes normally\n");
}
waitpid(child2,&status,0);
if(status == 0)
{
printf("Child 2 finishes normally\n");
}
close(fd2[0]);
close(fd2[1]);
close(fd[0]);
close(fd[1]);
close(fd3[1]);
close(fd3[0]);
}
}
int main(void)
{
square_plus1();
return 0;
}
答案 1 :(得分:2)
我最近遇到了同样的问题。经过大量的研究和测试,这是我在Docker团队中发现的......
https://github.com/docker/docker/issues/1676
是的,我们选择不遵循编号链接的符号链接因为 在不同的基础上可能发生的不一致结果 系统
基本上,它并不是一个即将到来的功能。
这是我的文件夹结构。两个存储库位于同一目录级别。
/cms-code
/cms-themes
我想将/public
内的/cms-code
文件夹符号链接到/cms-themes
文件夹。在Dockerfile
内/cms-code
建立COPY或将公共文件夹添加到图像中。不幸的是,我得到的只是一个复制到图像/容器中的符号链接,但没有任何内容。
我看到的选项:
cms-themes
回复/public
的{{1}}文件夹
库。 [对我的特殊情况不实用] /cms-code
将docker-compose
中的/public
文件夹设置为与我的主机/cms-code
目录同步。 [这最终是我的意思
选择。它仍然不理想,但确实有效。 CMS容器
(一旦运行)查看实际上/cms-themes
的所有内容
/public
。希望这有助于并与您的情况相关。如果您有任何疑问,请告诉我。如果您对作品中的卷不熟悉,我可以共享一个示例/cms-themes
文件。
更新 - 将撰写文件参考添加为Gist: https://gist.github.com/sgelliott/191c681ebb261c6a36ecd5fb70eb0176