[英]Docker Compose with React and Nginx
I'm trying to use docker-compose for deployment of my React app, which uses an express backend and Postgres Database.我正在尝试使用 docker-compose 来部署我的 React 应用程序,该应用程序使用快速后端和 Postgres 数据库。 My idea is to have shared volumes from my docker-compose.
我的想法是从我的 docker-compose 共享卷。 Then build from my Dockerfile into the volume, so that Nginx will be able to serve the files.
然后从我的 Dockerfile 构建到卷中,以便 Nginx 能够提供文件。 The problem now is that it works when i build the project the first time, but if I change something in my React Client and run "docker-compose up --build" it looks like everything is building as it should, but the files served are still the same.
现在的问题是,当我第一次构建项目时它可以工作,但是如果我在我的 React 客户端中更改某些内容并运行“docker-compose up --build”,它看起来一切都在按应有的方式构建,但是文件已提供还是一样。 Is COPY command in my dockerfile not overwriting the old files?
我的 dockerfile 中的 COPY 命令不会覆盖旧文件吗?
Dockerfile in my React Client Project我的 React 客户端项目中的 Dockerfile
FROM node:13.12.0-alpine as build
WORKDIR /app
COPY package.json ./
COPY package-lock.json ./
RUN npm install
COPY . ./
RUN npm run build
FROM node:13.12.0-alpine
COPY --from=build /app/build /var/lib/frontend
docker-compose docker-compose
version: "3.7"
services:
callstat_backend:
build: ./callstat-backend
restart: always
ports:
- "3000:3000"
env_file:
- keys.env
depends_on:
- postgres
callstat_frontend:
build: ./callstat-client
volumes:
- frontend/:/var/lib/frontend
postgres:
image: postgres:11.2-alpine
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: callstat
nginx:
image: nginx
volumes:
- frontend:/usr/share/nginx/html
- ./nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "80:80"
depends_on:
- callstat_frontend
volumes:
pgdata:
frontend:
Maybe i'm taking a totaly wrong approach here?也许我在这里采取了完全错误的方法?
You can run the commands in the following order:您可以按以下顺序运行命令:
# stop down the services
docker-compose stop
# remove the previously created docker resources
docker-compose rm
# bring up the services again
docker-compose up --build
This was your previous volume be removed and new one will be created with the updated changes.这是您之前的卷被删除,新的卷将使用更新的更改创建。
NOTE: This is okay from the development perspective, but docker volumes are really expected to persist between deployments.注意:从开发的角度来看,这没问题,但 docker 卷确实有望在部署之间持续存在。 For artifacts like code changes ideally images should be published as part of build process.
对于像代码更改这样的工件,理想情况下,图像应该作为构建过程的一部分发布。 To get little more insight into this topic you can refer to https://github.com/docker/compose/issues/2127
要深入了解这个主题,您可以参考https://github.com/docker/compose/issues/2127
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.