Docker Cookbook


Publishing Your Image to Docker Hub | 57



Download 6,31 Mb.
Pdf ko'rish
bet56/260
Sana21.04.2022
Hajmi6,31 Mb.
#570749
1   ...   52   53   54   55   56   57   58   59   ...   260
Bog'liq
Docker Cookbook

2.9 Publishing Your Image to Docker Hub | 57


See Also
• Docker Hub 
reference
2.10 Using ONBUILD Images
Problem
You have seen Dockerfiles in software repositories that have a single line like 
FROM
golang:1.3-onbuild
and you are wondering how this image can work.
Solution
The magic happens thanks to the 
ONBUILD
directive that you can use in a Dockerfile.
This directive defines a trigger that gets executed at a later time. The trigger is a regu‐
lar Dockerfile directive like 
RUN
or 
ADD
. An image containing 
ONBUILD
directives is
called a 
parent image
. When a parent image is used as a base image (i.e., using the
FROM
directive), the image being built—also called the child—triggers the directives
defined by 
ONBUILD
in the parent.
In other words, the parent image tells the child image what to do at build time.
You can still add directives in the Dockerfile of the child, but the 
ONBUILD
directives
of the parent will be executed first.
This is handy for building minimalistic Dockerfiles and providing consistency across
all your images.
Check the following references for examples of parent images that use the 
ONBUILD
image:

Node.js

Golang

Python

Ruby
For Node.js applications, for instance, you can use a parent image defined by this
Dockerfile:
FROM node:0.12.6
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
ONBUILD COPY package.json /usr/src/app/
58 | Chapter 2: Image Creation and Sharing


ONBUILD RUN npm install
ONBUILD COPY . /usr/src/app
CMD [ "npm", "start" ]
Your child image would be defined like this (at a minimum):
FROM node:0.12.6-onbuild
When building your child image, Docker would automatically copy the 
package.json
file from your local context to 
/usr/src/app
, it would execute 
npm install
and copy
the entire context to 
usr/src/app
.

Download 6,31 Mb.

Do'stlaringiz bilan baham:
1   ...   52   53   54   55   56   57   58   59   ...   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