Docker Cookbook


| Chapter 1: Getting Started with Docker



Download 6,31 Mb.
Pdf ko'rish
bet38/260
Sana21.04.2022
Hajmi6,31 Mb.
#570749
1   ...   34   35   36   37   38   39   40   41   ...   260
Bog'liq
Docker Cookbook

34 | Chapter 1: Getting Started with Docker


1.20 Copying Data to and from Containers
Problem
You have a running container started without any volume configuration, but you
would like to copy files in and out of the container.
Solution
Use the 
docker cp
command to copy files from a running container to the Docker
host. The 
docker cp
command allows you to copy files to and from the host to a con‐
tainer. The usage is as follows and is straightforward:
$ docker cp
docker: "cp" requires 2 arguments.
See 'docker cp --help'.
Usage: docker cp [OPTIONS] CONTAINER:PATH LOCALPATH|-
docker cp [OPTIONS] LOCALPATH|- CONTAINER:PATH
Copy files/folders between a container and your host.
...
Let’s illustrate this by first starting a container that will just sleep. You can enter the
container and create a file manually:
$ docker run -d --name testcopy ubuntu:14.04 sleep 360
$ docker exec -ti testcopy /bin/bash
root@b81793e9eb3e:/# cd /root
root@b81793e9eb3e:~# echo 'I am in the container' > file.txt
root@b81793e9eb3e:~# exit
Now to get the file that you just created in the container back in the host, 
docker cp
does the work:
$ docker cp testcopy:/root/file.txt .
$ cat file.txt
I am in the container
To copy from the host to the container, use 
docker cp
again but the other way
around:
$ echo 'I am in the host' > host.txt
$ docker cp host.txt testcopy:/root/host.txt
A nice use case is to copy from one container to another container, which is a matter
of combining the two methods by temporarily saving the files on the host. For exam‐
ple, if you want to transfer 
/root/file.txt
from two running containers with the names
c1
and 
c2
, use the following:

Download 6,31 Mb.

Do'stlaringiz bilan baham:
1   ...   34   35   36   37   38   39   40   41   ...   260




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish