Docker Cookbook



Download 6,31 Mb.
Pdf ko'rish
bet234/260
Sana21.04.2022
Hajmi6,31 Mb.
#570749
1   ...   230   231   232   233   234   235   236   237   ...   260
Bog'liq
Docker Cookbook

true
,
"dependencies"
:
{
"express"
:
"3.x"
},
"scripts"
:
{
"start"
:
"node app.js"
}
}
To create the Docker image, you can use the following Dockerfile:
FROM google/nodejs
WORKDIR /app
ADD package.json /app/
RUN npm install
ADD . /app
EXPOSE 8000
CMD []
ENTRYPOINT ["/nodejs/bin/npm", "start"]
This Dockerfile installs all the application dependencies and adds the application to
the image, ready to be started by using the 
ENTRYPOINT
instruction.
The order of the instructions in the Dockerfile is important.
Adding 
package.json
and installing dependencies before the addi‐
tion of the rest of the application will help to shorten the build time
in all cases when the application changes but dependencies remain
the same. This is because the ADD instruction invalidates the
Docker cache when any of copied files have been changed, and this
leads to the repetitive execution of all the commands that follow.
When you have your three files, you can build the Docker image and run a container:
$ docker build -t my_nodejs_image .
$ docker run -p 8000:8000 my_nodejs_image
This starts a container with the application built into the image by the 
ADD
instruc‐
tion. To be able to test your application changes, you can mount a volume with the
source into the container by using the following command:
$ docker run -p 8000:8000 -v "$PWD":/app my_nodejs_image
This mounts the current folder with the latest sources inside the container as the
application folder. This way, you can inject the latest sources during the development
without rebuilding the image.
10.1 CI/CD: Setting Up a Development Environment | 301


To share the images between the developers and push the images to alternative testing
environments, you can use a Docker registry. The following commands build and
push the image to the specified Docker registry:
$ docker build -t : \
/containersol/nodejs_app:
$ docker push :\
/containersol/nodejs_app:
To simplify the work with the development environment and ease the future integra‐
tion into a centralized testing environment, you can use the following three scripts:
build.sh

test.sh
, and 
push.sh
. These scripts will become a single command interface
for every common operation you are required to perform during the development.
build.sh
:
#!/bin/bash
# The first parameter passed to this script will be used as an image version.
# If none is passed, latest will be used as a tag.
if [ -z "${1}" ]; then
version="latest"
else
version="${1}"
fi
cd nodejs_app
docker build -t localhost:5000/containersol/nodejs_app:${version} .
cd ..
test.sh
:
#!/bin/bash
# The first parameter passed to this script will be used as an image version.
# If none is passed, latest will be used as a tag.
if [ -z "${1}" ]; then
version="latest"
else
version="${1}"
fi
docker run -d --name node_app_test -p 8000:8000 -v "$PWD":/app localhost:5000/ \
containersol/nodejs_app:${version}
echo "Testing image: localhost:5000/containersol/nodejs_app:${version}"
# Allow the webserver to start up
sleep 1
# Test will be successful if the webpage at the
# following URL includes the word “success”
curl -s GET http://localhost:8000 | grep success
status=$?

Download 6,31 Mb.

Do'stlaringiz bilan baham:
1   ...   230   231   232   233   234   235   236   237   ...   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