nginx 1개는 로드밸런스 역할
nginx 1개, apache2 1개는 웹서버 역할을 하도록 한다
지금까지는 nginx 로 접근하기 위해서 localhost:8081
apache2 로 접근하기 위해서 localhost:8082 로 접근해야 된다면
이제부터는 localhost:8080으로 접근하면 nginx, apache2가 순서대로 호출되는 결과를 확인해보자
파일 구조는 다음과 같다
/docker/loadbalance/Dockerfile
/docker/loadbalance/entrypoint.sh
/docker/loadbalance/default
/docker/nginx_ubuntu/Dockerfile
/docker/nginx_ubuntu/entrypoint.sh
/docker/apache_ubuntu/Dockerfile
/docker/apache_ubuntu/entrypoint.sh
/docker/docker-compose.yml
/docker/loadbalance/Dockerfile
FROM ubuntu:18.04
RUN apt update -y
RUN apt install vim -y
RUN apt install net-tools -y
RUN apt install iputils-ping -y
RUN apt install nginx -y
WORKDIR /
COPY ./loadbalance/entrypoint.sh /
RUN chmod 755 /entrypoint.sh
RUN rm -rf /etc/nginx/sites-available/default
COPY ./loadbalance/default /etc/nginx/sites-available/default
ENTRYPOINT ["./entrypoint.sh"]
/docker/loadbalance/entrypoint.sh
#!/bin/bash
sleep 1
service nginx start
sleep 1
/bin/bash
/docker/loadbalance/default
upstream myserver {
server apache_ubuntu:80;
server nginx_ubuntu:80;
}
server {
listen 80;
location / {
proxy_pass http://myserver;
}
}
/docker/nginx_ubuntu/Dockerfile
FROM ubuntu:18.04
RUN apt update -y
RUN apt install vim -y
RUN apt install net-tools -y
RUN apt install iputils-ping -y
RUN apt install nginx -y
WORKDIR /
COPY ./nginx_ubuntu/entrypoint.sh /
RUN chmod 755 /entrypoint.sh
ENTRYPOINT ["./entrypoint.sh"]
/docker/nginx_ubuntu/entrypoint.sh
#!/bin/bash
sleep 1
service nginx start
sleep 1
/bin/bash
/docker/apache_ubuntu/Dockerfile
FROM ubuntu:18.04
RUN apt update -y
RUN apt install vim -y
RUN apt install net-tools -y
RUN apt install iputils-ping -y
RUN apt install apache2 -y
WORKDIR /
COPY ./apache_ubuntu/entrypoint.sh /
RUN chmod 755 /entrypoint.sh
ENTRYPOINT ["./entrypoint.sh"]
/docker/apache_ubuntu/entrypoint.sh
#!/bin/bash
sleep 1
service apache2 start
sleep 1
/bin/bash
/docker/docker-compose.yml
version: '2'
services:
loadbalance:
hostname: loadbalance
container_name: loadbalance
build:
context: .
dockerfile: ./loadbalance/Dockerfile
stdin_open: true
tty: true
ports:
- 8080:80
apache_ubuntu:
hostname: apache_ubuntu
container_name: apache_ubuntu
build:
context: .
dockerfile: ./apache_ubuntu/Dockerfile
stdin_open: true
tty: true
ports:
- 8081:80
nginx_ubuntu:
hostname: nginx_ubuntu
container_name: nginx_ubuntu
build:
context: .
dockerfile: ./nginx_ubuntu/Dockerfile
stdin_open: true
tty: true
ports:
- 8082:80
docker-compose.yml 이 있는 위치에서
컨테이너 만드는 명령어를 입력하자
ls
pwd
docker-compose up -d
로컬의 웹 브라우저를 열고
localhost:8080에 접속해보자
새로고침을 5번 눌러보자