
--network=host 옵션을 사용하면 컨테이너가 별도의 네트워크 인터페이스를 생성하지 않고, 호스트의 네트워크를 그대로 사용한다.-p) 없이도 호스트의 IP로 접근 가능하다.--network=host)docker container run -d --name mynginx --network=host nginx
nginx 컨테이너를 실행하면서 --network=host 옵션을 적용.80 포트를 사용하면, 호스트의 80 포트도 동일하게 사용됨.ip address
출력 예시:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:0c:29:ee:de:b2 brd ff:ff:ff:ff:ff:ff
inet 192.168.2.10/24 brd 192.168.2.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
nginx 컨테이너가 별도의 네트워크를 가지지 않고, 호스트와 동일한 네트워크 인터페이스를 사용하는 것을 확인할 수 있음.docker container exec -it mynginx /bin/bash
ip address
출력 결과:
docker0 또는 eth0 인터페이스 없이, 호스트와 동일한 네트워크 설정을 가짐.curl http://localhost
nginx 서비스가 정상적으로 실행되는지 확인.<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>