docker - Nginx 不能与 docker-compose 一起用于 React 应用程序
问题描述
我已经创建了相同的 nginx 配置、DockerFile、Docker-compose 文件。
nginx/nginx.conf
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
DockerFile
FROM node:13.12.0-alpine as build
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json ./
COPY package-lock.json ./
RUN npm ci --silent
RUN npm install react-scripts@3.4.1 -g --silent
COPY . ./
RUN npm run build
# production environment
FROM nginx:stable-alpine
COPY --from=build /app/build /usr/share/nginx/html
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
码头工人-compose.yml
version: "3.7"
services:
client:
container_name: client
build:
context: .
dockerfile: Dockerfile
ports:
- 3001:3000
现在做完之后docker-compose up --build
我得到的日志为
client | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
client | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
client | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
client | 10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf
client | 10-listen-on-ipv6-by-default.sh: error: /etc/nginx/conf.d/default.conf differs from the packages version
client | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
client | /docker-entrypoint.sh: Configuration complete; ready for start up
我不确定,如果问题是由于不同的软件包版本或其他原因造成的,但是当尝试访问该 url 时,它说无法访问该站点。
解决方案
您没有指定您使用的 url,但看起来您的 nginx 在端口 80 上公开。您需要在 docker compose 中公开该端口。包括在端口下:
- 80:80
推荐阅读
- r - 如何在 Shiny 应用程序中汇总来自渲染函数外部的反应数据?
- python - Python Folium 模块标记(颜色问题)
- javascript - 使用jquery获取html()属性时无法获取更新后的表值
- sap-cloud-platform - 在事件触发器上将数据从 SAP S/4HANA 发送到 SAP 数据中心
- iframe - 如何让嵌入式谷歌表单滚动整个网页,而不是在它自己的框架内
- excel - Excel 中的条形码生成器宏无法识别文本中的空格 - “无效字符”
- python - 操纵此字典以返回所需的输出?
- python - unittest mock 如何模拟被调用的方法
- bash - BASH 构建动态命令
- sql - 创建联合查询的正确 MS Access SQL 语法是什么