How to copy data inside and outside the Docker container __docker

Source: Internet
Author: User
Tags postgresql docker ps docker cp docker run
Copy files from the container to the host
[Root@oegw1 soft]# Docker PS
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8d418a7b6021 Postgres "/docker-entrypoint. 7 hours ago up 7 hours Test1
[Root@oegw1 soft]# Docker exec-t-I. 8d418a7b6021/bin/bash
root@oegw1:/var/lib/postgresql# pwd
/var/lib/postgresql
root@oegw1:/var/lib/postgresql# ls
Data
root@oegw1:/var/lib/postgresql# exit
Exit
[Root@oegw1 soft]# Docker CP 8d418a7b6021:/var/lib/postgresql/data/opt/soft/
Complete copy
Docker Run-v/opt/soft:/mnt 8d418a7b6021


Copy files from host to container
1. Use-V Mount host data volume to container
With the-v argument, the host directory is preceded by a colon and must be an absolute path, followed by a colon-mounted path within the mirror.
[Root@oegw1 soft]# Docker run-it-v/opt/soft:/mnt Postgres/bin/bash
The disadvantage of this approach is that it can only be mounted when the container has just started
2. Copy to the container physical storage system directly on the host
[Root@oegw1 soft]# Docker PS
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8d418a7b6021 Postgres "/docker-entrypoint. 8 hours ago up 8 hours test1
[Root@oegw1 soft]# Docker inspect-f ' {{. Id} ' 8d418a7b6021
8d418a7b60216ed677ada5ca5fe1e82a953af6702837e8e05c95b16d23241d47
In Docker, it is actually mapped to/var/lib/docker/devicemapper/mnt/ 8d418a7b60216ed677ada5ca5fe1e82a953af6702837e8e05c95b16d23241d47/in this folder.
The file below is the contents of the root directory in Docker, and then we can copy it as we wish.

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.