Home > Operation and Maintenance > Docker > What to do if docker cp fails

What to do if docker cp fails

藏色散人
Release: 2022-10-21 14:47:15
Original
3459 people have browsed it

Solution to docker cp failure: 1. Open the command window; 2. Execute the "docker cp 312ee12b47a8:/opt/test.sh /mnt/www" command; 3. Execute "docker cp samba.1. x368e0ft61led8s2eu6ecxpmz:/opt/test.sh /mnt/www” command.

What to do if docker cp fails

The operating environment of this tutorial: linux7.3 system, docker version 19.03, Dell G3 computer.

What should I do if docker cp fails?

Docker cp command usage and error reporting (Error: No such container:path)

Reason

Need to use docker The docker cp command has been unable to fetch the files locally. I have also checked the cause of the error online. After trying again and again, I still get an error message such as "No such container:path: 312ee12b47a8:/opt/samba/user_data/app/test.sh" Such a mistake made me post a question. Fortunately, I had expert guidance and finally took out the file. Although it took a detour, I was relatively happy to have reached the end point.

Command Introduction

[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
Copy after login

docker cp use

There are different disputes about the docker specification method in the docker cp command. I saw these three methods on the Internet, using container id, long container id, and docker names. I verified these three methods and found that they can all be used normally. Everyone is happy.

Regarding docker path specification, the following three methods can be used for copy operations

CONTAINER ID and docker names can be viewed through a simple docker ps command. The method of obtaining the long CONTAINER ID will be introduced below. .

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 ~]#
Copy after login

2. Long 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 ~]#
Copy after login

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 ~]#
Copy after login

The above three methods are executed successfully

Recommended learning: "docker video tutorial"

The above is the detailed content of What to do if docker cp fails. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template