Docker 构建错误,存档/tar:不支持套接字

问题描述 投票:0回答:5

我是 Docker 新手,正在尝试构建镜像。 我成功地使用 Docker commit 命令执行此操作,但是当我尝试使用 Dockerfile 执行此操作时,出现以下错误:

shim@shim-Inspiron-5570:~$ sudo docker build -t shim/debian .
[sudo] password for shim: 
ERRO[0014] Can't add file /home/shim/.ServiceHub/bc1be858c1/116f2fb4b7 to tar: archive/tar: sockets not supported 
ERRO[0014] Can't add file /home/shim/.ServiceHub/bc1be858c1/11a6628921 to tar: archive/tar: sockets not supported 
ERRO[0014] Can't add file /home/shim/.ServiceHub/bc1be858c1/2cb20241cd to tar: archive/tar: sockets not supported 
ERRO[0014] Can't add file /home/shim/.ServiceHub/bc1be858c1/4964606154 to tar: archive/tar: sockets not supported 
ERRO[0014] Can't add file /home/shim/.ServiceHub/bc1be858c1/bc1be858c1 to tar: archive/tar: sockets not supported 
^Cnding build context to Docker daemon  1.725GB

Docker 文件如下所示:

FROM debian:shim
RUN apt-get update
RUN apt-get install -y git
RUN apt-get install -y vim

我使用的是 Ubuntu DeskTop 18.04 有人可以帮我吗?

linux docker dockerfile
5个回答
14
投票

看起来您的

Dockerfile
可能在
/home/shim/
中?

当您执行

docker build .
时,docker 将打包当前目录的内容并将其发送到 docker 守护进程。看起来
/home/shim/.ServiceHub
中的某些文件实际上是套接字,因此此操作失败。

最佳实践是将 Dockerfile 放在自己的独立目录中,以避免出现此类情况。

另外,我建议通读一下 dockerfile_best-practices,特别是关于

RUN
apt-get

的内容

4
投票

对于这个特定示例,您不应在

Dockerfile
中包含
/home/shim

在项目中的套接字 (

*.sock
) 文件的一般情况下,您可以将
*.sock
添加到您的 .dockerignore 文件中。


0
投票

嗨,我也面临同样的问题,并从这个问题中了解了原因。我的 Dockerfile 在一步中重新启动 MySQL,并创建一个名为 mysqld.sock 的文件,这是在构建映像时出现上述错误。 如果是这种情况,那么您可以在存储库本身中添加 .sock 文件,然后从那里使用它。


0
投票

也许这个答案已经晚了,但就我而言,原因是同一个项目在 Visual Studio 中打开,所以只有关闭它才对我有用


-1
投票

如果我们在主文件夹中启动命令

docker build
,就会出现错误。我的 Dockerfile 放置在子文件夹中,从 /home/$USER 调用
docker build -f /home/$USER/mydocker/Dockerfile
也会导致错误。

© www.soinside.com 2019 - 2024. All rights reserved.