Docker Cookbook


Copying Data to and from Containers | 35



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

1.20 Copying Data to and from Containers | 35


$ docker cp c1:/root/file.txt .
$ docker file.txt c2:/root/file.txt
Discussion
Prior to Docker 1.8, 
docker cp
did not support copying files from the host to a con‐
tainer. However, you could do it with a combination of 
docker exec
and some shell
redirection:
$ echo 'I am in the host' > host.txt
$ docker exec -i testcopy sh -c 'cat > /root/host.txt' < host.txt
$ docker exec -i testcopy sh -c 'cat /root/host.txt'
I am in the host
This is not needed anymore but is a good showcase of the power of the 
docker exec
command.
See Also
• The original idea for this recipe from 
Grigoriy Chudnov
36 | Chapter 1: Getting Started with Docker


CHAPTER 2
Image Creation and Sharing
2.0 Introduction
Quickly after discovering the basic principles of using Docker, you will want to create
your own container images. Maybe you will want to package an existing application
or you will want to build a new one from scratch leveraging Docker. This chapter is
about creating container images and sharing them with others.
The first concept around creating images is that you can start a container using a base
image and interactively make changes to it. Docker lets you keep those changes by
committing
them into a new image (see 
Recipe 2.1
). Under the covers, Docker keeps
track of the difference between your base image and your new image by creating a
new image layer using the union filesystem being used. Sharing this new image is as
easy as exporting it to a tar file and giving this tar file to others (see 
Recipe 2.2
).
But making changes to a container manually and committing them to a new images
is not highly reproducible and not automated. A better solution is to create a Docker‐
file that will let Docker build the image automatically (see 
Recipe 2.3
). You can go
through creating a Dockerfile for a simple Python-based Flask application in 
Recipe
2.4
, and in 
Recipe 2.5
you will learn the best practices to optimize this Dockerfile.
If you have used Vagrant and Packer before you will want to go through 
Recipe 2.7
and 
Recipe 2.8
; this will help you embrace Docker and build Docker images by re-
using your existing configuration management recipes.
Sharing images using the export and import feature works fine, but to share your
images with others and integrate Docker into a continuous integration pipeline you
can leverage the Docker Hub. The Docker Hub (see 
Recipe 2.9
) is nothing else than
an application store. Images on Docker Hub can be shared publicly, and they can also
37


be built automatically through integration with code hosting services like GitHub and
Bitbucket (see 
Recipe 2.12
).
Finally, if you do not want to use the Docker Hub, you can deploy your own Docker
images registry (
Recipe 2.11
) and set up your own automated build (
Recipe 2.13
).
At the end of this chapter you will be able to write Dockerfiles for your various appli‐
cation services and share them through a hosted service like the Docker Hub or
through your own Docker registry. This will put you on a quick path toward develop‐
ing continuous integration and deployment pipelines.

Download 6,31 Mb.

Do'stlaringiz bilan baham:
1   ...   35   36   37   38   39   40   41   42   ...   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