[Docker] 컨ν μ΄λ link μ€μ
1. link μ¬μ©νκΈ°
λ컀μμλ κ°μ bridge λ€νΈμν¬λ₯Ό μ¬μ©νλ 컨ν μ΄λλΌλ¦¬ ν΅μ ν μ μλ€. linkλ₯Ό μ¬μ©νλ©΄ 컨ν μ΄λμ μ΄λ¦ λλ λ³μΉμ μ§μ νμ¬ ν΅μ ν μ μλ€.
linkλ '--link 컨ν μ΄λ_μ΄λ¦' ννλ‘ --link μ΅μ μ ν΅ν΄ μ§μ νλ€.
λ¨ linkλ‘ μ°κ²°ν΄μ€ 컨ν μ΄λλ μ΄μ μ 미리 μμ±λμ΄μμ΄μΌ νλ€. μ°μ web 컨ν μ΄λλ₯Ό μμ±νλ€.
[user@localhost ~]$ docker container run -d --name web3 httpd:latest
827c38ecb011516344191485c051299e72852146ecaf55ca57ee242d9bc688cc
os6 컨ν
μ΄λλ₯Ό μ€νμν€λ©΄μ web3λ₯Ό λ§ν¬νλ€.
$docker run -idt os6 --link web3 centos:latest
curl λͺ λ Ήμ΄λ₯Ό ν΅ν΄ μ μ°κ²°λλ κ²μ νμΈν μ μλ€.
[user@localhost ~]$ docker exec os6 curl web3
<html><body><h1>It works!</h1></body></html>
/etc/hosts νμΌμ νμΈν΄λ³΄λ©΄ web3 κ° μλ κ²μ νμΈν μ μλ€.
ip μ£Όμ λ§μΌλ‘ μ°Ύμκ°λ κ²μ΄ μ΄λ ΅κΈ° λλ¬Έμ μ¬μ©νκΈ° νΈνλλ‘ μ΄λ¦μΌλ‘ λΆλ₯΄μκ³ λμ¨ κ²μ΄ host name μΈλ°, /etc/hosts νμΌμ dns μλ²μ λ¬Όμ΄λ³΄κΈ° μ μ μ°Έμ‘°νλ νμΌμ΄λ€.
[user@localhost ~]$ docker exec os6 cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2 web3 827c38ecb011
172.17.0.3 17ecbf6ecbc5
2. link μμ λ³μΉ μ¬μ©νκΈ°
--link 컨ν μ΄λμ΄λ¦:λ³μΉ μ ννλ‘ μ΅μ μ λΆμ¬μ£Όλ©΄ λ³μΉμΌλ‘λ μ μν μ μλ€.
[user@localhost ~]$ docker run -dit --name os7 --link web3:apache centos:7
web3컨ν μ΄λλ₯Ό λ§ν¬ν λ apacheλΌλ λ³μΉμ λΆμ¬μ€λ€.
[user@localhost ~]$ docker exec os7 cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2 apache 827c38ecb011 web3
172.17.0.5 6376de4531a2
apacheμ webλͺ¨λ 컨ν μ΄λ os7μ /etc/hosts νμΌμ λ±λ‘λμ΄μμμ νμΈν μ μλ€.
[user@localhost ~]$ docker exec os7 curl apache
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 45 100 45 0 0 8527 0 --:--:-- --:--:-- --:--:-- 9000
<html><body><h1>It works!</h1></body></html>
컨ν μ΄λμ΄λ¦ λΏλ§ μλλΌ apache λΌλ λ³μΉμΌλ‘λ μ κ·Ό κ°λ₯νλ€ !