[Docker] Host to container network

2023. 4. 19. 08:15·기타/Docker

 

 

실습 내용

Host OS 에서 nginx 를 설치하고

apache docker container 3개를 띄워 로드벨런싱해본다.

 

 

무엇을 배우나?

  • Container Load balancing
  • Container Network 설정

 

Q & A

Q1. Nginx on Container vs Host OS?

A1. 둘다 가능함. 단 Container 로 띄울거면 access-log 를 어디에 저장할지 잘 생각해야함. 공통으로 사용하는 volume 추천.

 

Q2. How to communicate among contaienrs on network?

A2. Many ways.

  • Use bridge network (docker0)
  • set custom docker bridge network with `docker network create <network-name>`  and set with same network when to start container
  • Use HOST Network with --network host
    (only used in linux)

 

Q3. What's docker bridge network?

A3. Refer to this post

 

 

실습

디렉토리 구조

apache 설정

Dockerfile

FROM httpd
COPY index.html /usr/local/apache2/htdocs/

index.html

<html>
<body>
    <h1>apache 1 / 2 / 3</h1>
</body>
</html>

apache number 를 1, 2, 3 총 3개 준비하고

container 실행시 apache index.html 경로에 붙여넣는다.

 

nginx 설정

Dockerfile

FROM nginx
COPY ./nginx.conf /etc/nginx/nginx.conf

nginx.conf

 

server url 을 "localhost" 로 지정하면 안된다.

보통은 docker 기본 bridge network 의 게이트웨이 도메인 172.17.0.1 을 사용하게 되는데

개발 환경에서는 `host.docker.internal` 이라는 Special DNS 도메인을 사용해도 좋다.

Docker 에 의해 자동으로 bridge netowork 게이트웨이 도메인 `172.17.0.1` 으로 변환된다. 

Container -> Host OS IP 주소에 접근하고자 할 때 사용한다.

The host has a changing IP address, or none if you have no network access.
We recommend that you connect to the special DNS name 
`host.docker.internal`
 which resolves to the internal IP address used by the host.
This is for development purpose and does not work in a production environment outside of Docker Desktop.

결과 화면

띄워진 nginx 컨테이너에 의해 총 3개의 apache container 로 로드밸런싱 되고있다.

기본 로드밸런싱 전략은 Round Robin 이다.

새로고침을 광클해본다.

 

 

 

Reference

 

Explore networking features

 

docs.docker.com

 

저작자표시 (새창열림)

'기타 > Docker' 카테고리의 다른 글

[Docker] credential  (0) 2024.08.09
[Docker] Docker network for communication among containers  (0) 2023.04.23
[Docker] volume with CLI  (0) 2022.05.19
[Docker] volume 사용팁  (0) 2022.05.18
[Docker] Docker compose  (0) 2021.12.20
'기타/Docker' 카테고리의 다른 글
  • [Docker] credential
  • [Docker] Docker network for communication among containers
  • [Docker] volume with CLI
  • [Docker] volume 사용팁
M_Falcon
M_Falcon
  • M_Falcon
    Falcon
    M_Falcon
  • 전체
    오늘
    어제
    • 분류 전체보기 (429)
      • Web (16)
        • Nodejs (14)
        • Javascript (23)
        • FrontEnd (4)
      • DataBase (39)
        • Fundamental (1)
        • Redis (4)
        • PostgreSQL (10)
        • NoSQL (4)
        • MySQL (9)
        • MSSQL (3)
        • Error (4)
      • Algorithm (79)
        • Algorithm (문제풀이) (56)
        • Algorithm (이론) (23)
      • JVM (64)
        • Spring (13)
        • JPA (5)
        • Kotlin (13)
        • Java (23)
        • Error (7)
      • 기타 (68)
        • Kafka (3)
        • Kubernetes (3)
        • Docker (12)
        • git (19)
        • 잡동사니 (26)
      • 재테크 (11)
        • 세무 (4)
        • 투자 (3)
        • 보험 (0)
      • BlockChain (2)
        • BitCoin (0)
      • C (32)
        • C (10)
        • C++ (17)
        • Error (3)
      • Low Level (8)
        • OS (3)
        • 시스템 보안 (5)
      • 네트워크 (3)
      • LINUX (30)
        • Linux (26)
        • Error (4)
      • 저작권과 스마트폰의 이해 (0)
      • 생각 뭉치 (6)
      • 궁금증 (2)
      • Private (4)
        • 이직 경험 (0)
        • 꿈을 찾아서 (1)
      • Android (21)
        • OS (4)
  • 블로그 메뉴

    • 홈
    • WEB
    • 알고리즘
    • DataBase
    • Linux
    • Mobile
    • C
    • 방명록
  • 링크

    • github
  • 공지사항

  • 인기 글

  • 태그

    Spring
    docker
    linux
    Kotlin
    알고리즘
    Git
    백준
    Bitcoin
    Programmers
    javascript
    PostgreSQL
    ubuntu
    database
    JPA
    android
    kafka
    algorithm
    java
    C++
    프로그래머스
  • hELLO· Designed By정상우.v4.10.3
M_Falcon
[Docker] Host to container network
상단으로

티스토리툴바