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 ~]#
上面三种方法执行都是成功的