0

I have a Docker file which build a react application, and then runs an nginx server to serve the resulting webpack. I use a multi-stage build, something like:

# Dockerfile
# build application
FROM node:14-alpine AS builder
... project cofiguration
RUN npm run build

# copy to nginx
FROM nginx:stable-alpine
COPY --from=builder /app/build /usr/share/nginx/html
... more setup here
// docker-compose.yaml
version: '3'
services:  
  frontend-nginx:
    build:
      context: frontend
    ports:
     ...

Now I need to add another web application, so I wish to split builder and nginx stages to separate Dockerfiles.

Is there a way to COPY --from in docker-compose.yaml? Should I simply save the output of builder to a shared volume, and access it at runtime from nginx?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
bavaza
  • 10,319
  • 10
  • 64
  • 103
  • They should either be two containers, so two NGINXs, or one container, so within one Dockerfile. – jonrsharpe Nov 26 '21 at 09:31
  • @jonrsharpe why do I need 2 containers? I have one nginx server, serving multiple applications. I just need to place the static pages from both app's webpack in the nginx container. – bavaza Nov 26 '21 at 09:37
  • You don't need two containers, which is why I gave the other option. – jonrsharpe Nov 26 '21 at 09:38
  • The 2nd option is what I have now, but the context is getting to cluttered to manage. I'm looking for a way to have 2 container (actually 1 per web application + 1 nginx), and just copy the static files to the final nginx container. Is that impossible in your opinion? – bavaza Nov 26 '21 at 09:39
  • You can use volumes in the "docker-compose.yml" file If you have the code in your machine. I'm not aware of another way to do something like that in docker-compose – Pedro Rodrigues Nov 26 '21 at 10:49

0 Answers0