【发布时间】:2020-01-20 12:50:08
【问题描述】:
我有一个 index.html 应用程序,它使用 nginx 执行 js 应用程序。 https://github.com/daleharvey/pacman
我想用 3 个应用程序容器和一个负载平衡来 dockerize 这个应用程序,他选择了 3 个容器中的 1 个循环算法。
但是我的html应用是用nginx的,我的负载均衡也是用nginx的?
我的 docker-compose.yml:
version: '3'
services:
pacman1:
build: ./pacman
pacman2:
build: ./pacman
pacman3:
build: ./pacman
nginx:
image: nginx:latest
container_name: production_nginx
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
ports: ['8000:80']
redis:
image: redis
ports: ['6379']
我的 html 应用程序的 Dockerfile:
#Start with current nginx
FROM nginx:latest
#Update package manager and install git
RUN apt-get update && apt-get install -y \
git
#Clean the html root dir
RUN rm -R /usr/share/nginx/html/
#Clone pacman app from git
RUN git clone https://github.com/daleharvey/pacman.git /usr/share/nginx/html/
#Modify files for web serving
RUN chmod -R 755 /usr/share/nginx/html/*
RUN chown -R www-data /usr/share/nginx/html/*
EXPOSE 3000
#USAGE:
# docker run --name pacman -d -p 8080:80 pacman
我的 nginx.conf
worker_processes 4;
events { worker_connections 1024; }
http {
upstream mysite {
least_conn;
server pacman1:3000;
server pacman2:3000;
server pacman3:3000;
}
server {
listen 8080;
server_name _;
root /usr/share/nginx/html;
index index.html;
location / {
proxy_pass http://mysite;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
}
请问,为什么它不起作用?因为 nginx 有默认端口 80 ?如何在没有 nginx 的情况下运行我的 html 应用程序?谢谢。
【问题讨论】:
标签: html docker nginx docker-compose dockerfile