Docker Compose with React and Nginx
我正在尝试使用docker-compose部署我的React应用程序,该应用程序使用快速后端和Postgres数据库。我的想法是从docker-compose共享卷。然后从我的Dockerfile构建到该卷中,以便Nginx将能够为这些文件提供服务。现在的问题是,当我第一次构建项目时,它可以工作,但是如果我在React Client中更改某些内容并运行" docker-compose up --build ",则看起来一切都在按需构建,但是投放的文件仍然相同。我的dockerfile中的COPY命令不会覆盖旧文件吗?
我的React Client项目中的Dockerfile
1 2 3 4 5 6 7 8 9 | 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 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: |
也许我在这里完全采用了错误的方法?
您可以按以下顺序运行命令:
1 2 3 4 5 6 7 8 | # 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 |
这是您先前的卷,将被删除,并且将使用更新后的更改来创建新卷。
注意:从开发的angular来看这是可以的,但实际上docker卷有望在两次部署之间持久存在。对于代码更改之类的工件,理想情况下,应在构建过程中发布图像。要获得对该主题的更多了解,您可以参考https://github.com/docker/compose/issues/2127