与Docker的Angular共享服务器中部署的错误
我在共享服务器中与Docker部署我的角度代码有问题。
这是我的docker-compose.yaml
# This file will use the Dockerfile to run a container with that image
version: "3.3"
services:
web:
# build: . will make Docker Compose run 'docker image build .'
# https://stackoverflow.com/questions/29480099/whats-the-difference-between-docker-compose-vs-dockerfile
build:
context: .
dockerfile: Dockerfile
image: test/angular
#Nginx Service
nginx-web:
image: nginx:alpine
container_name: nginx-web
restart: always
tty: true
ports:
- 443:443
- 80:80
networks:
- app-network
volumes:
- ./docker-configs/nginx/conf.d:/etc/nginx/conf.d
- ./docker-configs/nginx/ssl/:/etc/ssl/
# If we wanted more services, we'll put them right here
#redis:
#image: "redis:alpine"
#Docker Networks
networks:
app-network:
driver: bridge
我的dockerfile
###############################################################################
# Stage 1: Compile and Build angular codebase
###############################################################################
# Use official node image as the base image
FROM node:16.0-alpine as node
# Set the working directory
WORKDIR /app
# Add the source code to app
COPY . /app
# Install all the dependencies
RUN npm install
# Generate the build of the application
RUN npm run build
# Stage 2: Serve app with nginx server
# Use official nginx image as the base image
FROM nginx:latest
RUN apt update
RUN apt install vim libgpm2 vim-common vim-runtime xxd gpm vim-doc vim-scripts
# Copy the build output to replace the default nginx contents.
COPY --from=node /app/dist/web /usr/share/nginx/html
COPY /docker-configs/nginx/conf.d/nginx-custom.conf /etc/nginx/conf.d/default.conf
# Expose port 80
EXPOSE 80
,这是
server {
listen 80;
listen 443 ssl;
server_name test-angular.eu;
ssl_certificate /etc/ssl/domain.tld.chained.crt;
ssl_certificate_key /etc/ssl/domain.tld.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html =404;
}
}
我运行docker-compose的nginx-custom.conf,无法访问页面test-angular.eu。但是,当我进入服务器的IP时,Nginx正在工作。
我在做什么错?
谢谢大家。
I have a problem with the deployment of my angular code with docker in a shared server.
This is my docker-compose.yaml
# This file will use the Dockerfile to run a container with that image
version: "3.3"
services:
web:
# build: . will make Docker Compose run 'docker image build .'
# https://stackoverflow.com/questions/29480099/whats-the-difference-between-docker-compose-vs-dockerfile
build:
context: .
dockerfile: Dockerfile
image: test/angular
#Nginx Service
nginx-web:
image: nginx:alpine
container_name: nginx-web
restart: always
tty: true
ports:
- 443:443
- 80:80
networks:
- app-network
volumes:
- ./docker-configs/nginx/conf.d:/etc/nginx/conf.d
- ./docker-configs/nginx/ssl/:/etc/ssl/
# If we wanted more services, we'll put them right here
#redis:
#image: "redis:alpine"
#Docker Networks
networks:
app-network:
driver: bridge
my Dockerfile
###############################################################################
# Stage 1: Compile and Build angular codebase
###############################################################################
# Use official node image as the base image
FROM node:16.0-alpine as node
# Set the working directory
WORKDIR /app
# Add the source code to app
COPY . /app
# Install all the dependencies
RUN npm install
# Generate the build of the application
RUN npm run build
# Stage 2: Serve app with nginx server
# Use official nginx image as the base image
FROM nginx:latest
RUN apt update
RUN apt install vim libgpm2 vim-common vim-runtime xxd gpm vim-doc vim-scripts
# Copy the build output to replace the default nginx contents.
COPY --from=node /app/dist/web /usr/share/nginx/html
COPY /docker-configs/nginx/conf.d/nginx-custom.conf /etc/nginx/conf.d/default.conf
# Expose port 80
EXPOSE 80
and this is my nginx-custom.conf
server {
listen 80;
listen 443 ssl;
server_name test-angular.eu;
ssl_certificate /etc/ssl/domain.tld.chained.crt;
ssl_certificate_key /etc/ssl/domain.tld.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html =404;
}
}
after i run docker-compose up, the page test-angular.eu is not accessible. But when i go to ip of my server, nginx is working.
What am I doing wrong?
Thank you to everyone.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论