Docker Practice 7: Container-to-host copy data

Source: Internet
Author: User
Tags docker ps docker cp

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.