Docker 구성요소 / 접근 방법INFRA/Doker2024. 7. 28. 23:47
Table of Contents
Docker 구성요소 / 접근 방법
- 호스트에서 Docker 브리지 네트워크를 통해 웹 서버 컨테이너에 접근
- 도커엔진 기본 : 172.17 변경 불가
- 웹 서버와 애플리케이션 서버(예: 톰캣)가 서로 다른 포트 번호를 사용하는 이유
- 충돌을 피하고 역할을 명확하게 구분하기 위해 통상적으로 쓰는 번호 사용 → 애초에 이미지가 다름
- IP를 확인해보았다.
--localhost addr
root@docker:~# ip addr
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
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
--host ubuntu
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:14:e0:9a brd ff:ff:ff:ff:ff:ff
inet 10.100.0.105/24 brd 10.100.0.255 scope global noprefixroute enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::b7d4:f0bc:72a6:91af/64 scope link noprefixroute
valid_lft forever preferred_lft forever
--bridge
3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:71:11:45:b4 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
inet6 fe80::42:71ff:fe11:45b4/64 scope link
valid_lft forever preferred_lft forever
11: veth54916c0@if10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
link/ether da:e2:38:d0:be:75 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet6 fe80::d8e2:38ff:fed0:be75/64 scope link
valid_lft forever preferred_lft forever
임의의 IP로 컨테이너 생성
- 도커 엔진 기본 : 172.17 변경불가
- 근데 다른 아이피 쓰고 싶으면 user defined bridge network 생성
root@docker:~# docker network create --driver bridge --subnet 192.168.100.0/24 --gateway 192.168.100.254 mynet
0c078cb1cfcfeb80aa6152214b22236b1cd4b64aaa396856b10503b3e5f39413
root@docker:~# docker network ls
NETWORK ID NAME DRIVER SCOPE
792ca527876d bridge bridge local
53f7b047ac80 host host local
0c078cb1cfcf mynet bridge local
9d8171228e89 none null local
root@docker:~# docker run -d --name appjs --net mynet --ip 192.168.100.100 -p 8080:8080 sinhye/nodejs
root@docker:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dd9028c958e3 powermvp/marvel-collection "nginx -g 'daemon of…" 6 minutes ago Up 6 minutes 80/tcp, 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp appjs
root@docker:~# docker inspect mynet
"Config": [
{
"Subnet": "192.168.100.0/24",
"Gateway": "192.168.100.254"
}
"IPv4Address": "192.168.100.100/24",
- 접근 완료
'INFRA > Doker' 카테고리의 다른 글
Docker image 경량화 (0) | 2024.07.29 |
---|---|
Docker Image registry : pravate, hub.docker.com (0) | 2024.07.29 |
Docker 명령어 정리 (0) | 2024.07.28 |