Docker Cookbook


Using Packer to Create a Docker Image | 51



Download 6,31 Mb.
Pdf ko'rish
bet52/260
Sana21.04.2022
Hajmi6,31 Mb.
#570749
1   ...   48   49   50   51   52   53   54   55   ...   260
Bog'liq
Docker Cookbook

2.8 Using Packer to Create a Docker Image | 51


{
"builders"
:
[
{
"type"
:
"docker"
,
"image"
:
"ubuntu:14.04"
,
"commit"
:
"true"
}
],
"provisioners"
:
[
{
"type"
:
"shell"
,
"script"
:
"bootstrap.sh"
}
],
"post-processors"
:
[
{
"type"
:
"docker-tag"
,
"repository"
:
"how2dock/packer"
,
"tag"
:
"latest"
}
]
}
You can validate the template and launch a build of the image with two commands:
$ packer validate template.json
$ packer build template.json
Set up several builders in your template and output different
images for your application (e.g., Docker and AMI).
To help you test Packer, I created a Vagrantfile that starts an Ubuntu 14.04 virtual
machine, installs Docker on it, and downloads Packer. Test it like this:
$ git clone https://github.com/how2dock/docbook.git
$ cd ch02/packer
$ vagrant up
$ vagrant ssh
$ cd /vagrant
$ /home/vagrant/packer validate template.json
Template validated successfully.
$ /home/vagrant/packer build template.json
...
==> docker: Creating a temporary directory for sharing data...
==> docker: Pulling Docker image: ubuntu:14.04
...
==> Builds finished. The artifacts of successful builds are:
--> docker: Imported Docker image: 3ebae8e2f2a8af8f2c5f366c603091c5e9c8e234bff8
--> docker: Imported Docker image: how2dock/packer:latest
52 | Chapter 2: Image Creation and Sharing


$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
how2dock/packer latest 3ebae8e2f2a8 20 seconds ago 210.8 MB
ubuntu 14.04 8eaa4ff06b53 11 days ago 192.7 MB
In this example, you can now run Nginx (which has been installed via the 
boostrap.sh
script):
$ docker run -d -p 80:80 how2dock/packer /usr/sbin/nginx -g "daemon off;"
But because a Dockerfile was not used to create this image, no 
CMD
or 
ENTRYPOINT
was
defined. Nginx will not be started when the container is launched; hence a container
started from the image generated without specifying how to run Nginx will exit right
away.
Discussion
Packer is a great tool that can help you migrate some of your work from previous
DevOps workflows into a Docker-based workflow. However, Docker containers run
applications in the foreground and encourage running single-application processes
per container. Hence, creating a Docker image with Packer that would have, for
example, MySQL, Nginx, and WordPress in the same image would be contrary to the
Docker philosophy and might prove difficult to run without some additional manual
post-processing with something like Supervisor (see 
Recipe 1.15
).
The preceding solution features a basic shell provisioning. If you have existing con‐
figuration management recipes, you can also use them to create a Docker image.
Packer features shell, Ansible, Chef, Puppet, and Salt 
provisioners
. As an example, the
template-ansible.json
file in the repository used previously makes use of the Ansible
local provisioner. The Packer template gets modified like so:
{

Download 6,31 Mb.

Do'stlaringiz bilan baham:
1   ...   48   49   50   51   52   53   54   55   ...   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