我使用 -v ./file.zip:/root/file.zip 将 .zip 文件安装到我的 docker 容器中
ls显示/root/下有file.zip,但unzip却说该文件不存在。
docker run --name container_name -v ./file.zip:/root/file.zip image_name ls /root/ -al && unzip /root/file.zip
total 16156
drwx------ 1 root root 4096 Dec 8 01:12 .
drwxr-xr-x 1 root root 4096 Dec 8 01:12 ..
-rw-r--r-- 1 root root 3106 Oct 15 2021 .bashrc
drwxr-xr-x 3 root root 4096 Dec 8 00:54 .cache
-rw-r--r-- 1 root root 161 Jul 9 2019 .profile
-rw-r--r-- 1 root root 16521251 Dec 6 19:52 file.zip
unzip: cannot find or open /root/file.zip, /root/file.zip.zip or /root/file.zip.ZIP.
我尝试将 file.zip 安装在另一层下:/root/directory/file.zip 但这也有同样的问题。
我在我的设置上运行以下命令,它有效:
docker run -it --name container_name -v $(pwd)/file.zip:/root/file.zip ubuntu:20.04 sh -c 'ls /root/ -al && apt update && apt install unzip && unzip /root/file.zip && ls -la'
输出:
drwx------ 1 root root 4096 Dec 8 02:14 .
drwxr-xr-x 1 root root 4096 Dec 8 02:14 ..
-rw-r--r-- 1 root root 3106 Dec 5 2019 .bashrc
-rw-r--r-- 1 root root 161 Dec 5 2019 .profile
-rwxrwxrwx 1 1000 1000 31633 Dec 8 02:04 file.zip
Archive: /root/file.zip
inflating: file.txt
命令中缺少部分:-it、完整文件路径 ($(pwd))、sh -c 和 ''。
我认为你的命令应该是(请在 file.zip 的位置运行,或给出绝对路径):
docker run -it --name container_name -v $(pwd)/file.zip:/root/file.zip image_name sh -c 'ls /root/ -al && unzip /root/file.zip'