ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • docker 2
    docker 2023. 10. 5. 12:12

    다시 한번 실행 해보기

    app.py

    import time

    import redis
    from flask import Flask

    app = Flask(__name__)
    cache = redis.Redis(host='redis', port=6379)

    def get_hit_count():
        retries = 5
        while True:
            try:
                return cache.incr('hits')
            except redis.exceptions.ConnectionError as exc:
                if retries == 0:
                    raise exc
                retries -= 1
                time.sleep(0.5)

    @app.route('/')
    def hello():
        count = get_hit_count()
        return 'Hello World! I have been seen {} times.\n'.format(count)

    ========================================
    requirements.txt 

    flask
    redis
    =======================================
    Dockerfile

    FROM python:3.7-alpine 
    WORKDIR /code 
    ENV FLASK_APP=app.py      
    ENV FLASK_RUN_HOST=0.0.0.0   
    RUN apk add --no-cache gcc musl-dev linux-headers
    COPY requirements.txt requirements.txt
    RUN pip install -r requirements.txt      
    EXPOSE 5000
    COPY . .
    CMD ["flask", "run"]      

    ====================================
    docker-compose.yml

    version: "3.9"
    services:
      web:
        build: .
        ports:
          - "8000:5000"
        volumes:
          - .:/code
        environment:
          FLASK_ENV: development
      redis:
        image: "redis:alpine"
        volumes:
          - .:/data

     

     

     

    docker-compose.yml

    version: "3"

    services:
        nginxproxy:
            image: nginx:1.18.0
            ports:
                - "8080:8080"
                - "8081:8081"
            restart: always
            volumes:
                - "./nginx/nginx.conf:/etc/nginx/nginx.conf"

        nginx:
            depends_on:
                - nginxproxy
            image: nginx:1.18.0
            restart: always

        apache:
            depends_on:
                - nginxproxy
            image: httpd:2.4.46
            restart: always

    nginx.conf

    user nginx;
    worker_processes  auto;

    error_log  /var/log/nginx/error.log warn;
    pid        /var/run/nginx.pid;

    events { 
        worker_connections 1024; 
    }

    http {
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
        access_log  /var/log/nginx/access.log  main;    
        sendfile on;
        keepalive_timeout 65;

        upstream docker-nginx {
            server nginx:80;
        }

        upstream docker-apache {
            server apache:80;
        }

        server {
            listen 8080;

            location / {
                proxy_pass         http://docker-nginx;
                proxy_redirect     off;
                proxy_set_header   Host $host;
                proxy_set_header   X-Real-IP $remote_addr;
                proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header   X-Forwarded-Host $server_name;
            }
        }

        server {
            listen 8081;

            location / {
                proxy_pass         http://docker-apache;
                proxy_redirect     off;
                proxy_set_header   Host $host;
                proxy_set_header   X-Real-IP $remote_addr;
                proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header   X-Forwarded-Host $server_name;
            }
        }
    }


    nginx.conf 에 내용 처럼 아파치와 nginx가 나왔다

     

    docker-compose.yml

    version: "3"

    services:
        nginxproxy:
            image: nginx:1.18.0
            ports:
                - "80:80" -> 포트만 변경
            restart: always
            volumes:
                - "./nginx/nginx.conf:/etc/nginx/nginx.conf"

        nginx:
            depends_on:
                - nginxproxy
            image: nginx:1.18.0
            restart: always

        apache:
            depends_on:
                - nginxproxy
            image: httpd:2.4.46
            restart: always

    nginx.conf

    user nginx;
    worker_processes  auto;

    error_log  /var/log/nginx/error.log warn;
    pid        /var/run/nginx.pid;

    events { 
        worker_connections 1024; 
    }

    http {
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
        access_log  /var/log/nginx/access.log  main;    
        sendfile on;
        keepalive_timeout 65;

        upstream docker-nginx {
            server nginx:80;
        }

        upstream docker-apache {
            server apache:80;
        }

        server {
            listen 80;

            location /blog/ { -> 경로 변경
                proxy_pass         http://docker-nginx;
                proxy_redirect     off;
                proxy_set_header   Host $host;
                proxy_set_header   X-Real-IP $remote_addr;
                proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header   X-Forwarded-Host $server_name;
            }

            location /community/-> 경로 변경
                proxy_pass         http://docker-apache;
                proxy_redirect     off;
                proxy_set_header   Host $host;
                proxy_set_header   X-Real-IP $remote_addr;
                proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header   X-Forwarded-Host $server_name;
            }
        }

    }


    블로그로 접속이 되지만 안에 내용이없어 이런 화면이 나온다

     

    nginx
    docker exec -it dockertest-nginx-1 /bin/bash
    cd /usr/share/nginx/html -> 블로그 생성    

    apache
    docker exec -it dockertest-apache-1 /bin/bash

    cd /usr/local/apache2/htdocs/






     

    'docker' 카테고리의 다른 글

    docker (jenkins)  (0) 2023.10.10
    docker (주문앱 배포)  (1) 2023.10.10
    docker 4 (grafana)  (0) 2023.10.10
    docker 3 (volume)  (1) 2023.10.06
    docker  (0) 2023.10.04
Designed by Tistory.