Docker and host file interlock

Source: Internet
Author: User
Tags docker ps docker cp docker run

From: http://blog.csdn.net/yangzhenping/article/details/43667785 Click Open link


How to copy data inside and outside the Docker container.

Copy files from the container to the host [plain] view plain copy docker CP <containerid>:/file/path/within/container/host/path/target

Copy files from host to container


Reference from:

Http://stackoverflow.com/questions/22907231/copying-files-from-host-to-docker-container
1. Use-V Mount host data volume to container


[Plain] View plain copy docker run-v/path/to/hostdir:/mnt $container copy in Container Cp/mnt/sourcefile/path/to/destfile


2. Copy to the container physical storage system directly on the host


A. Get the container name or ID:
[Plain] View plain copy $ docker PS


B. Get the ID of the entire container
[Plain] View plain copy $ docker inspect-f ' {{. ID} ' Step a gets the name or ID


C. Copy files on the host:
[Plain] View plain copy $ sudo cp path-file-host/var/lib/docker/aufs/mnt/full_container_id/path-new-file or $ sudo CP Path-file-host/var/lib/docker/devicemapper/mnt/123abc<<id>>/rootfs/root


Example:
[plain]  View plain  copy $ docker ps      container id       image    command       created       STATUS       PORTS         NAMES      D8e703d7e303   solidleon/ssh:latest       /usr/sbin/sshd -D                       cranky_pare      $ docker inspect -f    ' {{. Id} '  cranky_pare      or    $ docker inspect -f     ' {{. Id} '  d8e703d7e303      d8e703d7e3039a6df6d01bd7fb58d1882e592a85059eb16c4b83cf91847f88e5      $&NBSP;SUDO&Nbsp;cp file.txt /var/lib/docker/aufs/mnt/** d8e703d7e3039a6df6d01bd7fb58d1882e592a85059eb16c4b83cf91847f88e5  


3. With the input output character


[Plain] View plain copy docker run-i ubuntu/bin/bash-c ' cat >/path/to/container/file ' </path/to/host/file/


Or
[Plain] View plain copy docker exec-it <container_id> bash-c ' cat >/path/to/container/file ' </path/to/ho st/file/




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.