这就是我的docker-compose的样子。我在开发过程中使用了angular 4200端口和spring boot 8080端口。现在我想将备份端口更改为80,但是当我这样做时,我的前端不能再从后端检索数据。
api:
image: api-dev
network_mode: bridge
container_name: api
expose:
- 8080
ports:
- 8080:8080
volumes:
- data:/file-storage
ui:
image: ui-dev
network_mode: bridge
container_name: ui
ports:
- 80:80
environment:
- API_URL=http://dev.website.com:8080
- API_HOST=172.26.0.2
- API_PORT=8080
depends_on:
- api
volumes:
data:代理设置:
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html = 404;
}
location /api/ {
proxy_pass http://${HOST}:${PORT};
}
}DockerFile内部:
ENV URL http://dev.website.com
ENV HOST 172.17.0.3
ENV PORT 80
### Copy Custom nginx conf
COPY ./docker-config/nginx-dev.conf /tmp/nginx-custom.conf
#COPY ./nginx-custom.conf /etc/nginx/conf.d/default.conf
# When the container starts, replace the env.js with values from environment variables
CMD ["/bin/sh", "-c", "envsubst '${HOST},${PORT}' < /tmp/nginx-custom.conf > /etc/nginx/conf.d/default.conf && envsubst < /usr/share/nginx/html/assets/env.template.js > /usr/share/nginx/html/assets/env.js && exec nginx -g 'daemon off;'"]
Thanks 发布于 2020-06-09 18:04:40
要让springboot监听80,您需要为您的api容器设置env SERVER_PORT=80。但我认为你的Nginx代理和Dockerfile太复杂了。1,在我看来,您可以将api (springboot)保持在8080上,并更改nginx代理配置
location /api/ {
proxy_pass http://api:8080;
}2、硬编码IP地址不是必须的,当您将容器部署到其他Docker主机时可能会出现问题。因此您可以移除所有固定的IP地址,容器之间可以通过内部DNS名称(服务名称)进行通信。
https://stackoverflow.com/questions/62276309
复制相似问题