用户登录
用户注册

分享至

docker cp 失败怎么办

  • 作者: Zoan
  • 来源: 51数据库
  • 2022-10-24

docker cp失败的解决办法:1、打开命令窗口;2、执行“docker cp 312ee12b47a8:/opt/test.sh /mnt/www”命令;3、执行“docker cp samba.1.x368e0ft61led8s2eu6ecxpmz:/opt/test.sh /mnt/www”命令即可。

本教程操作环境:linux7.3系统、docker19.03版、Dell G3电脑。

docker cp 失败怎么办?

docker cp命令使用及报错(Error: No such container:path)处理

原由

需要把docker中的文件取到本地,docker cp命令一直不能成功,错误原因也在网上查了,一遍遍尝试还是报诸如“No such container:path: 312ee12b47a8:/opt/samba/user_data/app/test.sh”这样的错误,发了个提问,幸好有高手指点,总算把文件给取出来了,虽然是绕道而行,但是比较到达终点,还是比较开心的

命令介绍

[root@d8a4ced9-4996-52cb-a ~]# docker cp --help
Usage: docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH
Copy files/folders between a container and the local filesystem
Use ‘-’ as the source to read a tar archive from stdin
and extract it to a directory destination in a container.
Use ‘-’ as the destination to stream a tar archive of a
container source to stdout.
Options:
-a, --archive Archive mode (copy all uid/gid information)
-L, --follow-link Always follow symbol link in SRC_PATH

docker cp使用

对于docker cp命令中关于docker指定方法有不同争议,网上看到有这三种方法,使用容器id、长容器id、docker names,我对这三种方式进行了验证,发现都可以正常使用,皆大欢喜。

关于docker的路径指定,以下三种方式都可以做拷贝操作

CONTAINER ID 、docker names可以通过简单的docker ps命令查看,长CONTAINER ID的获取方法下面会介绍。

1、CONTAINER ID

[root@d8a4ced9-4996-52cb-a93c-d ~]# docker cp 312ee12b47a8:/opt/test.sh /mnt/www
[root@d8a4ced9-4996-52cb-a93c-d ~]# ls /mnt/www/
111.tar  test.sh
[root@d8a4ced9-4996-52cb-a93c-d ~]#

2、长 CONTAINER ID

[root@d8a4ced9-4996-52cb-a93c-d ~]# docker inspect 312ee12b47a8 |grep 312ee12b47a8
        "Id": "312ee12b47a8ec00dfb4e36912387350e36bdba566ef7ee87347893db596bc85",
        "ResolvConfPath": 
        ......
            "Hostname": "312ee12b47a8",
                        "312ee12b47a8"
                        "312ee12b47a8"
[root@d8a4ced9-4996-52cb-a93c-d ~]# docker cp 312ee12b47a8ec00dfb4e36912387350e36bdba566ef7ee87347893db596bc85:/opt/test.sh /mnt/www
[root@d8a4ced9-4996-52cb-a93c-d ~]# rm -rf /mnt/www/test.sh 
[root@d8a4ced9-4996-52cb-a93c-d ~]# docker cp 312ee12b47a8ec00dfb4e36912387350e36bdba566ef7ee87347893db596bc85:/opt/test.sh /mnt/www
[root@d8a4ced9-4996-52cb-a93c-d ~]# ls /mnt/www/
111.tar  test.sh
[root@d8a4ced9-4996-52cb-a93c-d ~]#

3、docker NAMES

[root@d8a4ced9-4996-52cb-a93c-d ~]# rm -rf /mnt/www/test.sh 
[root@d8a4ced9-4996-52cb-a93c-d ~]# docker cp samba.1.x368e0ft61led8s2eu6ecxpmz:/opt/test.sh /mnt/www
[root@d8a4ced9-4996-52cb-a93c-d ~]# ls /mnt/www/
111.tar  test.sh
[root@d8a4ced9-4996-52cb-a93c-d ~]#

上面三种方法执行都是成功的

软件
前端设计
程序设计
Java相关