docker cp: copying files from the container to the host, copy files from the host to the vessel

The problem encountered in the learning process, the container is created when there is no host to mount directories, making it impossible to share files between the host and the container, so he thought of how to copy from the container copy the files to the host or from the host file to the container. The method is simple, recorded for everyone to share in the blog.

First, by docker psdetermining the name of the container, we assume that the container name to nginx-web.

First, copy the file from the container to the host

Now we want to container /home/licence.txtcopy the files to the host /homedirectory. Execute the following command:

docker cp nginx-web:/home/licence.txt /home

Second, copy the file from the host to the vessel

Now we want to host the /home/licence.txtcopied files to the container /homedirectory. Execute the following command:

docker cp /home/licence.txt nginx-web:/home

Note that, regardless of the container has not started, the copy command will take effect. Article content represents only personal point of view, if the place is not correct, welcome criticism and thank you.

Published 180 original articles · won praise 297 · Views 1.64 million +

Guess you like

Origin blog.csdn.net/claram/article/details/104322078