Docker Practice 7: Container and host copy data

Source: Internet
Author: User
Tags docker ps docker cp

Use the-v parameter in Docker Practice 2 to associate the host with the related directory in the container (mount), so we can use this channel to place the data that we want to copy with each other so that we can copy the file with the CP command.

In addition to this approach, we can also use different commands to copy the data. copy data from a container like a host

Docker provides the CP command, as follows:

# docker PS
CONTAINER ID        IMAGE                     COMMAND                CREATED             STATUS              PORTS                         NAMES        
a77a72ac178c        tutum/apache-php:latest   "/run.sh"              hours ago up        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
copying data from the host to the container

This is to use a magic channel provided by the Docker to complete the data transfer from the host to the container.
First you get the full ID of the container using the Docker inspect method,

Inspect return   low-level information on a container

Then use the/var/lib/docker/aufs/mnt/channel to complete the copy.
Examples are 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

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.