无法构建 docker 容器:无法将文件 <file> 添加到 tar: io: read/write on closed pipe
Unable to build docker container: Can't add file <file> to tar: io: read/write on closed pipe
我正在尝试通过 ssh 从 mac 在 raspberry pi 上构建容器。我将 DOCKER_HOST
设置为 ssh://root@192.168.1.11
(192.168.1.11 是我 raspberry pi 的 IP)。
docker 构建命令失败并显示以下错误消息:
ERRO[0000] Can't add file /Users/brian/git/github/proj/backend/apps/accounts/managers.py to tar: io: read/write on closed pipe
ERRO[0000] Can't close tar writer: io: read/write on closed pipe
error during connect: Post "http://docker/v1.24/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&shmsize=0&t=localhost%3A5000%2Fbackend%3Ae150d93&target=&ulimits=null&version=1": write |1: broken pipe
我 mac 上的 docker 版本是:
docker --version
Docker version 20.10.7, build f0df350
我的 raspberry pi 上的 docker 版本是:
docker --version
Docker version 20.10.7, build 20.10.7-0ubuntu1~20.04.1
我正在尝试构建的容器使用此 Docker 文件:
FROM --platform=linux/amd64 python:3.9
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip3 install -r requirements.txt
ADD . /code/
RUN useradd -m app
USER app
我可以在我的 mac 和 raspberry pi.
上使用这个 Docker 文件构建图像
我在 SO/GitHub 上发现了其他一些可能相关的问题:
- Docker "Can't add file <path> to tar: readlink <path> The system cannot find the file specified"
以下是来自 raspberry pi 的更多信息:
ubuntu@ubuntu:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.8G 0 3.8G 0% /dev
tmpfs 782M 2.8M 779M 1% /run
/dev/mmcblk0p2 29G 14G 15G 49% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/mmcblk0p1 253M 120M 133M 48% /boot/firmware
tmpfs 782M 0 782M 0% /run/user/1000
关于 raspberry pi 我无法从失败的构建命令中查找日志。如果我在 raspberry pi 上重新启动 docker:
sudo systemctl restart docker
然后获取日志:
sudo journalctl -fu docker.service
然后 运行 再次执行 docker 构建命令,当我再次 运行 sudo journalctl -fu docker.service
时我没有看到任何新日志。
还有其他方法可以调试失败的 docker 构建命令吗?
这是来自我的 raspberry pi 的 docker info
:
ubuntu@ubuntu:~$ docker info
Client:
Context: default
Debug Mode: false
Server:
Containers: 21
Running: 1
Paused: 0
Stopped: 20
Images: 95
Server Version: 20.10.7
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version:
runc version:
init version:
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 5.4.0-1029-raspi
Operating System: Ubuntu 20.04.2 LTS
OSType: linux
Architecture: aarch64
CPUs: 4
Total Memory: 7.628GiB
Name: ubuntu
ID: 24DG:6BVV:K3TX:HT64:4U2M:DFHX:2RQA:ENP5:J2WC:V3VS:UKV3:M3TL
Docker Root Dir: /var/lib/docker
Debug Mode: false
Username: briancaffey
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: No memory limit support
WARNING: No swap limit support
WARNING: No kernel memory TCP limit support
WARNING: No oom kill disable support
更新 8/8/2021:我的 raspberry pi 和 Mac 之间没有基于证书的 SSH 访问设置。将 -l "debug"
添加到我的 docker build
命令中,这更清楚:
DEBU[0000] commandconn: starting ssh with [-l ubuntu -- 192.168.1.11 docker system dial-stdio]
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):ubuntu@192.168.1.11: Permission denied (publickey,password).
DEBU[0000] commandconn: starting ssh with [-l ubuntu -- 192.168.1.11 docker system dial-stdio]
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):ubuntu@192.168.1.11: Permission denied (publickey,password).
DEBU[0000] commandconn: starting ssh with [-l ubuntu -- 192.168.1.11 docker system dial-stdio]
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):ubuntu@192.168.1.11: Permission denied (publickey,password).
DEBU[0000] commandconn: starting ssh with [-l ubuntu -- 192.168.1.11 docker system dial-stdio]
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):ubuntu@192.168.1.11: Permission denied (publickey,password).
DEBU[0000] commandconn: starting ssh with [-l ubuntu -- 192.168.1.11 docker system dial-stdio]
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):ubuntu@192.168.1.11: Permission denied (publickey,password).
ERRO[0000] Can't add file <file> to tar: io: read/write on closed pipe
ERRO[0000] Can't close tar writer: io: read/write on closed pipe
DEBU[0000] FIXME: Got an status-code for which error does not match any expected type!!!: -1 module=api status_code=-1
error during connect: Post "http://docker/v1.24/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&shmsize=0&t=localhost%3A5000%2Fbackend%3Ae150d93&target=&ulimits=null&version=1": write |1: broken pipe
我已经解决了最初的问题,但我现在面临着关于平台兼容性的评论中提出的一个单独的问题。我不得不在基本图像中从 Python 3.9 切换到 Python 3.8,并且还在基本图像中指定了 --platform="linux/arm64"
:
FROM --platform="linux/arm64" python:3.8
我的 raspberry pi 和 Mac 之间没有基于证书的 SSH 访问设置。将 -l "debug"
添加到我的 docker build
清楚地表明了这一点:
DEBU[0000] commandconn: starting ssh with [-l ubuntu -- 192.168.1.11 docker system dial-stdio]
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):ubuntu@192.168.1.11: Permission denied (publickey,password).
DEBU[0000] commandconn: starting ssh with [-l ubuntu -- 192.168.1.11 docker system dial-stdio]
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):ubuntu@192.168.1.11: Permission denied (publickey,password).
DEBU[0000] commandconn: starting ssh with [-l ubuntu -- 192.168.1.11 docker system dial-stdio]
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):ubuntu@192.168.1.11: Permission denied (publickey,password).
DEBU[0000] commandconn: starting ssh with [-l ubuntu -- 192.168.1.11 docker system dial-stdio]
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):ubuntu@192.168.1.11: Permission denied (publickey,password).
DEBU[0000] commandconn: starting ssh with [-l ubuntu -- 192.168.1.11 docker system dial-stdio]
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):ubuntu@192.168.1.11: Permission denied (publickey,password).
ERRO[0000] Can't add file <file> to tar: io: read/write on closed pipe
ERRO[0000] Can't close tar writer: io: read/write on closed pipe
DEBU[0000] FIXME: Got an status-code for which error does not match any expected type!!!: -1 module=api status_code=-1
error during connect: Post "http://docker/v1.24/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&shmsize=0&t=localhost%3A5000%2Fbackend%3Ae150d93&target=&ulimits=null&version=1": write |1: broken pipe
要为我的 raspberry pi 设置 passworldless 身份验证,我遵循了这个指南:https://www.raspberrypi.org/documentation/remote-access/ssh/passwordless.md
此外,为了在 raspberry pi 上构建容器,我需要将 python:3.8
基础映像与平台 linux/arm64
一起使用。这是我使用的 docker build
命令:
docker \
-l "debug" \
build \
--platform linux/arm64 \
-t $REGISTRY/backend:$VERSION \
-f backend/Dockerfile \
./backend/
我正在尝试通过 ssh 从 mac 在 raspberry pi 上构建容器。我将 DOCKER_HOST
设置为 ssh://root@192.168.1.11
(192.168.1.11 是我 raspberry pi 的 IP)。
docker 构建命令失败并显示以下错误消息:
ERRO[0000] Can't add file /Users/brian/git/github/proj/backend/apps/accounts/managers.py to tar: io: read/write on closed pipe
ERRO[0000] Can't close tar writer: io: read/write on closed pipe
error during connect: Post "http://docker/v1.24/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&shmsize=0&t=localhost%3A5000%2Fbackend%3Ae150d93&target=&ulimits=null&version=1": write |1: broken pipe
我 mac 上的 docker 版本是:
docker --version
Docker version 20.10.7, build f0df350
我的 raspberry pi 上的 docker 版本是:
docker --version
Docker version 20.10.7, build 20.10.7-0ubuntu1~20.04.1
我正在尝试构建的容器使用此 Docker 文件:
FROM --platform=linux/amd64 python:3.9
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip3 install -r requirements.txt
ADD . /code/
RUN useradd -m app
USER app
我可以在我的 mac 和 raspberry pi.
上使用这个 Docker 文件构建图像我在 SO/GitHub 上发现了其他一些可能相关的问题:
- Docker "Can't add file <path> to tar: readlink <path> The system cannot find the file specified"
以下是来自 raspberry pi 的更多信息:
ubuntu@ubuntu:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.8G 0 3.8G 0% /dev
tmpfs 782M 2.8M 779M 1% /run
/dev/mmcblk0p2 29G 14G 15G 49% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/mmcblk0p1 253M 120M 133M 48% /boot/firmware
tmpfs 782M 0 782M 0% /run/user/1000
关于 raspberry pi 我无法从失败的构建命令中查找日志。如果我在 raspberry pi 上重新启动 docker:
sudo systemctl restart docker
然后获取日志:
sudo journalctl -fu docker.service
然后 运行 再次执行 docker 构建命令,当我再次 运行 sudo journalctl -fu docker.service
时我没有看到任何新日志。
还有其他方法可以调试失败的 docker 构建命令吗?
这是来自我的 raspberry pi 的 docker info
:
ubuntu@ubuntu:~$ docker info
Client:
Context: default
Debug Mode: false
Server:
Containers: 21
Running: 1
Paused: 0
Stopped: 20
Images: 95
Server Version: 20.10.7
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version:
runc version:
init version:
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 5.4.0-1029-raspi
Operating System: Ubuntu 20.04.2 LTS
OSType: linux
Architecture: aarch64
CPUs: 4
Total Memory: 7.628GiB
Name: ubuntu
ID: 24DG:6BVV:K3TX:HT64:4U2M:DFHX:2RQA:ENP5:J2WC:V3VS:UKV3:M3TL
Docker Root Dir: /var/lib/docker
Debug Mode: false
Username: briancaffey
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: No memory limit support
WARNING: No swap limit support
WARNING: No kernel memory TCP limit support
WARNING: No oom kill disable support
更新 8/8/2021:我的 raspberry pi 和 Mac 之间没有基于证书的 SSH 访问设置。将 -l "debug"
添加到我的 docker build
命令中,这更清楚:
DEBU[0000] commandconn: starting ssh with [-l ubuntu -- 192.168.1.11 docker system dial-stdio]
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):ubuntu@192.168.1.11: Permission denied (publickey,password).
DEBU[0000] commandconn: starting ssh with [-l ubuntu -- 192.168.1.11 docker system dial-stdio]
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):ubuntu@192.168.1.11: Permission denied (publickey,password).
DEBU[0000] commandconn: starting ssh with [-l ubuntu -- 192.168.1.11 docker system dial-stdio]
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):ubuntu@192.168.1.11: Permission denied (publickey,password).
DEBU[0000] commandconn: starting ssh with [-l ubuntu -- 192.168.1.11 docker system dial-stdio]
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):ubuntu@192.168.1.11: Permission denied (publickey,password).
DEBU[0000] commandconn: starting ssh with [-l ubuntu -- 192.168.1.11 docker system dial-stdio]
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):ubuntu@192.168.1.11: Permission denied (publickey,password).
ERRO[0000] Can't add file <file> to tar: io: read/write on closed pipe
ERRO[0000] Can't close tar writer: io: read/write on closed pipe
DEBU[0000] FIXME: Got an status-code for which error does not match any expected type!!!: -1 module=api status_code=-1
error during connect: Post "http://docker/v1.24/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&shmsize=0&t=localhost%3A5000%2Fbackend%3Ae150d93&target=&ulimits=null&version=1": write |1: broken pipe
我已经解决了最初的问题,但我现在面临着关于平台兼容性的评论中提出的一个单独的问题。我不得不在基本图像中从 Python 3.9 切换到 Python 3.8,并且还在基本图像中指定了 --platform="linux/arm64"
:
FROM --platform="linux/arm64" python:3.8
我的 raspberry pi 和 Mac 之间没有基于证书的 SSH 访问设置。将 -l "debug"
添加到我的 docker build
清楚地表明了这一点:
DEBU[0000] commandconn: starting ssh with [-l ubuntu -- 192.168.1.11 docker system dial-stdio]
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):ubuntu@192.168.1.11: Permission denied (publickey,password).
DEBU[0000] commandconn: starting ssh with [-l ubuntu -- 192.168.1.11 docker system dial-stdio]
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):ubuntu@192.168.1.11: Permission denied (publickey,password).
DEBU[0000] commandconn: starting ssh with [-l ubuntu -- 192.168.1.11 docker system dial-stdio]
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):ubuntu@192.168.1.11: Permission denied (publickey,password).
DEBU[0000] commandconn: starting ssh with [-l ubuntu -- 192.168.1.11 docker system dial-stdio]
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):ubuntu@192.168.1.11: Permission denied (publickey,password).
DEBU[0000] commandconn: starting ssh with [-l ubuntu -- 192.168.1.11 docker system dial-stdio]
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):Permission denied, please try again.
EBU[0000] commandconn (ssh):ubuntu@192.168.1.11: Permission denied (publickey,password).
ERRO[0000] Can't add file <file> to tar: io: read/write on closed pipe
ERRO[0000] Can't close tar writer: io: read/write on closed pipe
DEBU[0000] FIXME: Got an status-code for which error does not match any expected type!!!: -1 module=api status_code=-1
error during connect: Post "http://docker/v1.24/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&shmsize=0&t=localhost%3A5000%2Fbackend%3Ae150d93&target=&ulimits=null&version=1": write |1: broken pipe
要为我的 raspberry pi 设置 passworldless 身份验证,我遵循了这个指南:https://www.raspberrypi.org/documentation/remote-access/ssh/passwordless.md
此外,为了在 raspberry pi 上构建容器,我需要将 python:3.8
基础映像与平台 linux/arm64
一起使用。这是我使用的 docker build
命令:
docker \
-l "debug" \
build \
--platform linux/arm64 \
-t $REGISTRY/backend:$VERSION \
-f backend/Dockerfile \
./backend/