Docker implements file transfer between container and host

In Docker practice 2 , the -v parameter is used to associate (mount) the host with the relevant directory in the container, so we can use this channel to put the data we want to copy each other into, so that we can use the cp command to copy files .

In addition to this method, we can also use different commands to copy data.

Copy data from container to host

Docker provides the cp command, which is used as follows:
# docker ps
CONTAINER ID        IMAGE                     COMMAND                CREATED             STATUS              PORTS                         NAMES        
a77a72ac178c        tutum/apache-php:latest   "/run.sh"              21 hours ago        Up 21 hours         0.0.0.0:8080->80/tcp          phpapache_phpapache_1
# docker-enter a77a72ac178c
root@a77a72ac178c:~# ls /var/www/html
index.php  logo.png
root@a77a72ac178c:~# exit
logout

# docker cp a77a72ac178c:/var/www/html /var/www/
# ls /var/www/
app  download  index.html
# ls /var/www/app/
index.php  logo.png

Copy data from host to container

Here, a magical channel provided by docker is used to complete the data transfer from the host to the container. 
First use the docker inspect method to get the full id of the container,

 inspect   Return low-level information on a container

Then use the /var/lib/docker/aufs/mnt/ channel to complete the copy. 
An example is as follows:

# docker inspect -f '{{.Id}}' a77a72ac178c
a77a72ac178c1e35708d2af446197c10239b0b1bd8932104578e334b83eb93a2
# cp docker/docker-start.sh /var/lib/docker/aufs/mnt/a77a72ac178c1e35708d2af446197c10239b0b1bd8932104578e334b83eb93a2/root/
# docker-enter a77a72ac178c
# pwd
/root
# ls
docker-start.sh

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326571392&siteId=291194637