diff --git a/README.md b/README.md index a5a9b3a..a0cc6c9 100644 --- a/README.md +++ b/README.md @@ -16,3 +16,6 @@ ## Run - Run command `docker-compose up` - Access to http://localhost/ + +## Thanks +https://www.adictosaltrabajo.com/2017/06/22/balanceando-apps-de-spring-boot-con-nginx-en-docker/ diff --git a/docker-compose.yaml b/docker-compose.yaml index 5c9bdc4..e745666 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,23 +1,45 @@ version: '3' services: nginx: - container_name: some-nginx - image: nginx:1.13 - restart: always - ports: - - 80:80 - - 443:443 - volumes: - - ./nginx/conf.d:/etc/nginx/conf.d - depends_on: - - app - - app: + build: + dockerfile: ./nginx/nginx.dockerfile + context: . + container_name: my-nginx + image: armandoss/my-nginx + restart: always + ports: + - 80:80 + depends_on: + - "app1" + - "app2" + - "app3" + app1: + hostname: app1 + restart: always + build: ./app + working_dir: /app + volumes: + - ./app:/app + ports: + - 8081:8081 + command: mvn clean spring-boot:run -Drun.jvmArguments='-Dserver.port=8081' + app2: + hostname: app2 + restart: always + build: ./app + working_dir: /app + volumes: + - ./app:/app + ports: + - 8082:8082 + command: mvn clean spring-boot:run -Drun.jvmArguments='-Dserver.port=8082' + app3: + hostname: app3 restart: always build: ./app working_dir: /app volumes: - ./app:/app - expose: - - "8080" - command: mvn clean spring-boot:run + ports: + - 8083:8083 + command: mvn clean spring-boot:run -Drun.jvmArguments='-Dserver.port=8083' \ No newline at end of file diff --git a/nginx/conf.d/app.conf b/nginx/conf.d/app.conf deleted file mode 100644 index 4860514..0000000 --- a/nginx/conf.d/app.conf +++ /dev/null @@ -1,20 +0,0 @@ -server { - listen 80; - charset utf-8; - access_log off; - - location / { - proxy_pass http://app:8080; - proxy_set_header Host $host:$server_port; - proxy_set_header X-Forwarded-Host $server_name; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - } - - location /static { - access_log off; - expires 30d; - - alias /app/static; - } -} diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..c383a76 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,11 @@ +upstream my-app { + server 172.17.0.1:8081 weight=1; + server 172.17.0.1:8082 weight=1; + server 172.17.0.1:8083 weight=1; +} + +server { + location / { + proxy_pass http://my-app; + } +} \ No newline at end of file diff --git a/nginx/nginx.dockerfile b/nginx/nginx.dockerfile new file mode 100644 index 0000000..794fa16 --- /dev/null +++ b/nginx/nginx.dockerfile @@ -0,0 +1,3 @@ +FROM nginx +RUN rm /etc/nginx/conf.d/default.conf +COPY /nginx/nginx.conf /etc/nginx/conf.d/default.conf \ No newline at end of file