Docker Cookbook


Running Hello World in Docker | 21



Download 6,31 Mb.
Pdf ko'rish
bet27/260
Sana21.04.2022
Hajmi6,31 Mb.
#570749
1   ...   23   24   25   26   27   28   29   30   ...   260
Bog'liq
Docker Cookbook

1.11 Running Hello World in Docker | 21


tainer. As soon as you exit this terminal, the container will stop running just like our
first 
hello world
example.
If you skipped the first few recipes on installing Docker, you should
try the web 
emulator
. It will give you a 10-minute tour of Docker,
and you will get your first practice with it.
1.12 Running a Docker Container in Detached Mode
Problem
You know how to run a container interactively but would like to run a service in the
background.
Solution
Use the 
-d
option of 
docker run
.
To try this, you will run a simple HTTP server with Python in a 
python:2.7
Docker
image pulled from 
Docker Hub
 (see also 
Recipe 2.9
):
$ docker run -d -p 1234:1234 python:2.7 python -m SimpleHTTPServer 1234
$ docker ps
CONTAINER ID IMAGE COMMAND ... NAMES
0fae2d2e8674 python:2.7 "python -m SimpleHTT ... suspicious_pike
If you open your browser at the IP of your Docker host on port 1234, you will see the
listing of the root directory inside your container. Docker automatically creates a cor‐
rect port mapping between the container and host port 1234, thanks to the 
-p
1234:1234
option. In 
Recipe 3.2
, you will learn more about this networking behavior.
Discussion
The 
-d
option makes the container run in the background. You can connect to the
container by using the 
exec
command and running a bash shell:
$ docker exec -ti 9d7cebd75dcf /bin/bash
root@9d7cebd75dcf:/# ps -ef | grep python
root 1 0 0 15:42 ? 00:00:00 python -m SimpleHTTPServer 1234
Lots of other options are 
available
 for 
docker run
. Experiment by specifying a name
for the container, changing the working directory of the container, setting an envi‐
ronment variable, and so on.

Download 6,31 Mb.

Do'stlaringiz bilan baham:
1   ...   23   24   25   26   27   28   29   30   ...   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