Using the-v parameter in Docker Practice 2 links the host to the relevant directory in the container (mount), so we can use this channel to put the data we want to copy with each other, so that we can use the CP command to copy the file.
In addition to this approach, we can also use different commands to copy the data separately.
Copy data from a container like a host
Docker provides the CP command with the following usage:
# docker PSCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a77a72ac178c Tutum/apache-php:latest"/run.sh" +Hours ago Up +Hours0.0.0.0:8080- the/tcp Phpapache_phpapache_1# Docker-enter a77a72ac178cRoot@a77a72ac178c:~# ls/var/www/htmlIndex. PHP Logo.pngroot@a77a72ac178c:~# ExitLogout# docker CP a77a72ac178c:/var/www/html/var/www/# ls/var/www/App DownloadIndex. html# ls/var/www/app/Index. PHP logo.png
Copying data from the host to the container
A magical channel provided by Docker is used to complete the data transfer from the host to the container.
The first thing to do is to use the Docker inspect method to get the container's full ID.
inspect Return low-levelon a container
Then use the/var/lib/docker/aufs/mnt/channel to complete the copy.
Examples are as follows:
# docker inspect -f ‘{{.Id}}‘ a77a72ac178ca77a72ac178c1e35708d2af446197c10239b0b1bd8932104578e334b83eb93a2# cp docker/docker-start.sh /var/lib/docker/aufs/mnt/a77a72ac178c1e35708d2af446197c10239b0b1bd8932104578e334b83eb93a2/root/# docker-enter a77a72ac178c# pwd/root# lsdocker-start.sh
Docker Practice 7: Container-to-host copy data