Centos 7 시스템 Docker 환경 에서 Nginx 역방향 에이전트

6889 단어 Dockernginx
목차
1. nginx 미 러
2.Docker Compose
1. nginx 미 러
1. nginx 미 러
[root@localhost ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
27833a3ba0a5: Pull complete 
ea005e36e544: Pull complete 
d172c7f0578d: Pull complete 
Digest: sha256:e71b1bf4281f25533cf15e6e5f9be4dac74d2328152edf7ecde23abc54e16c1c
Status: Downloaded newer image for nginx:latest

2. 테스트 를 바로 실행 할 수 있다
[root@localhost ~]# docker run -d -p 8080:80 nginx
[root@localhost ~]# curl -I  http://localhost:8080
HTTP/1.1 200 OK
Server: nginx/1.15.12
Date: Thu, 25 Apr 2019 14:39:08 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 16 Apr 2019 13:08:19 GMT
Connection: keep-alive
ETag: "5cb5d3c3-264"
Accept-Ranges: bytes
[root@localhost ~]# 

2.Docker Compose
Docker Compose 는 복잡 한 응용 프로그램 을 정의 하고 실행 하 는 Docker 도구 입 니 다.Compose 를 사용 하면 한 파일 에서 여러 용기 응용 프로그램 을 정의 한 다음 명령 을 사용 하여 응용 프로그램 을 시작 하고 모든 준 비 를 완료 할 수 있 습 니 다.
1. Docker Compose 설치
홈 페이지 설치 강좌: Docker Compose 설치
홈 페이지 에서 최신 버 전 을 가 져 올 수 있 습 니 다.
[root@localhost ~]# sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   617    0   617    0     0    752      0 --:--:-- --:--:-- --:--:--   752
100 15.4M  100 15.4M    0     0  1731k      0  0:00:09  0:00:09 --:--:-- 2687k
[root@localhost ~]# 
[root@localhost ~]# chmod +x /usr/local/bin/docker-compose
[root@localhost ~]# docker-compose --version
docker-compose version 1.24.0, build 0aa59064

2. docker - compose. yml 만 들 기
Dcoker Compse 의 실행 파일 은 docker - compose. yml 이기 때문에 테스트 항목 아래 docker - compose. yml 파일 을 만 듭 니 다.
[root@localhost ~]# cd Documents/DockerWeb
[root@localhost DockerWeb]# touch docker-compose.yml

이 파일 을 편집 하고 다음 내용 을 기록 하 며 종료 저장 합 니 다.
version: '2'
services:
    docker-web:
        container_name: docker-web-compose
        build: .

    reverse-proxy:
        container_name: reverse-proxy
        image: nginx
        ports:
         - "9090:8080"
        volumes:
         - ./proxy.conf:/etc/nginx/conf.d/default.conf

#            ,         :
#   docker-web,                     docker-web-compose   。
#   reverse-proxy,    nginx        ,       volumes            ,           proxy.conf。

proxy. conf 프로필 만 들 기
[root@localhost DockerWeb]# touch proxy.conf

이 파일 을 편집 하고 다음 내용 을 기록 하 며 종료 저장 합 니 다.
server {
    listen 8080;

    location / {
      proxy_pass http://docker-web:5000;
    }
}

#            :proxy_pass http://docker-web:5000;,  ip        docker-compose.yml            docker-web。

만 든 후에 이 디 렉 터 리 의 내용 을 봅 시다.
[root@localhost DockerWeb]# ll
total 356
-rw-r--r--. 1 root root    146 Apr 24 14:04 appsettings.Development.json
-rw-r--r--. 1 root root    105 Apr 24 14:04 appsettings.json
-rw-r--r--. 1 root root    287 Apr 25 14:55 docker-compose.yml
-rw-r--r--. 1 root root    137 Apr 24 14:51 Dockerfile
-rw-r--r--. 1 root root 228338 Apr 24 14:41 DockerWeb.deps.json
-rw-r--r--. 1 root root   9216 Apr 24 14:35 DockerWeb.dll
-rw-r--r--. 1 root root   1924 Apr 24 14:35 DockerWeb.pdb
-rw-r--r--. 1 root root    224 Apr 24 14:41 DockerWeb.runtimeconfig.json
-rw-r--r--. 1 root root  78848 Apr 24 14:35 DockerWeb.Views.dll
-rw-r--r--. 1 root root   5496 Apr 24 14:35 DockerWeb.Views.pdb
-rw-r--r--. 1 root root     92 Apr 25 14:54 proxy.conf
-rw-r--r--. 1 root root    526 Apr 24 14:41 web.config
drwxr-xr-x. 6 root root     71 Apr 24 22:48 wwwroot

3. Compose 실행
[root@localhost DockerWeb]# docker-compose up -d
Creating network "dockerweb_default" with the default driver
Building docker-web
Step 1/6 : FROM microsoft/dotnet:latest
 ---> e268893be733
Step 2/6 : WORKDIR /app
 ---> Using cache
 ---> 636e51b35e60
Step 3/6 : COPY . /app
 ---> 26c5b7a83367
Step 4/6 : EXPOSE 5000
 ---> Running in 54796fcb8c07
Removing intermediate container 54796fcb8c07
 ---> 6663d8b3df8f
Step 5/6 : ENV ASPNETCORE_URLS http://*:5000
 ---> Running in a6d66985a77e
Removing intermediate container a6d66985a77e
 ---> 586c4cc1cf75
Step 6/6 : ENTRYPOINT ["dotnet","DockerWeb.dll"]
 ---> Running in 812c66d16d72
Removing intermediate container 812c66d16d72
 ---> 8da5e977ec16
Successfully built 8da5e977ec16
Successfully tagged dockerweb_docker-web:latest
WARNING: Image for service docker-web was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating docker-web-compose ... done
Creating reverse-proxy      ... done
[root@localhost DockerWeb]# 

실행 이 끝 난 후에 우 리 는 거울 과 용기 에 해당 하 는 내용 이 있 는 지 볼 수 있 고 마지막 으로 curl 로 테스트 할 수 있다.
[root@localhost DockerWeb]# docker images
REPOSITORY             TAG                 IMAGE ID            CREATED              SIZE
dockerweb_docker-web   latest              8da5e977ec16        About a minute ago   1.74GB
nginx                  latest              27a188018e18        8 days ago           109MB
microsoft/dotnet       latest              e268893be733        2 weeks ago          1.74GB
[root@localhost DockerWeb]# docker ps
CONTAINER ID        IMAGE                  COMMAND                  CREATED              STATUS              PORTS                            NAMES
72584de2c725        nginx                  "nginx -g 'daemon of…"   About a minute ago   Up About a minute   80/tcp, 0.0.0.0:9090->8080/tcp   reverse-proxy
1b3adbbe8ec0        dockerweb_docker-web   "dotnet DockerWeb.dll"   About a minute ago   Up About a minute   5000/tcp                         docker-web-compose
dd45358d8c37        nginx                  "nginx -g 'daemon of…"   About an hour ago    Up About an hour    0.0.0.0:8080->80/tcp             friendly_bhaskara
[root@localhost DockerWeb]# docker-compose ps
       Name                Command          State               Ports             
----------------------------------------------------------------------------------
docker-web-compose   dotnet DockerWeb.dll   Up      5000/tcp                      
reverse-proxy        nginx -g daemon off;   Up      80/tcp, 0.0.0.0:9090->8080/tcp
[root@localhost DockerWeb]# curl -I http://localhost:9090
HTTP/1.1 200 OK
Server: nginx/1.15.12
Date: Thu, 25 Apr 2019 15:01:41 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive

[root@localhost DockerWeb]# 

참고 블 로그:
. NET Core 용기 화 된 다 중 용기 응용 배치 (Docker - Compose)

좋은 웹페이지 즐겨찾기