Docker Cookbook


Finding the IP Address of a Container



Download 6,31 Mb.
Pdf ko'rish
bet64/260
Sana21.04.2022
Hajmi6,31 Mb.
#570749
1   ...   60   61   62   63   64   65   66   67   ...   260
Bog'liq
Docker Cookbook

3.1 Finding the IP Address of a Container
Problem
You have started a container and would like to find its IP address.
Solution
There are many ways to find the IP address of a container started with the default
Docker networking. This recipe presents a few of them.
70 | Chapter 3: Docker Networking


The first method is to use the 
docker inspect
 command (see 
Recipe 9.1
 for details)
and the Go template format:
$ docker run -d --name nginx nginx
$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' nginx
172.17.0.2
You can also use the 
docker exec
command and check the IP address by using a
command that executes within the container:
$ docker exec -ti nginx ip add | grep global
inet 172.17.0.2/16 scope global eth0
You could also check the 
/etc/hosts
file in the container, assuming the image does set it
properly:
$ docker run -d --name foobar -h foobar busybox sleep 300
$ docker exec -ti foobar cat /etc/hosts | grep foobar
172.17.0.4 
foobar
Finally, you can enter a shell in the container and issue standard Linux commands at
the prompt:
$ docker exec -ti nginx bash
root@a3c1f7edb00a:/# cat /etc/hosts
See Also
• To understand how Docker networking works and go beyond finding a container
IP address, see 
Recipe 3.4
• 10 
examples
of how to get a Docker container IP address
3.2 Exposing a Container Port on the Host
Problem
You want to access a service running in a container over the network.
Solution
Docker can dynamically map a network port in a container to a port on the host by
using the 
-P
option of 
docker run
. You can also manually specify a mapping by using
the 
-p
option.
Let’s say that you have built an image that runs a Python Flask application using the
Dockerfile shown here:

Download 6,31 Mb.

Do'stlaringiz bilan baham:
1   ...   60   61   62   63   64   65   66   67   ...   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