Dockerfile copy one docker build to another docker file

  docker, docker-compose, dockerfile

I want to copy one dockerfile buid to another dockerfile.

Currently my dockerfile is mulit-stage build.

This is my current and it is only one file which is working very well.

FROM node:14.1-alpine as build

WORKDIR /app
COPY . /app

ENV PATH /app/node_modules/.bin:$PATH

RUN yarn config delete proxy
RUN npm config rm proxy


# Satisfy node requirements
RUN npm config rm https-proxy
RUN npm install
RUN npm run build

# nginx 
FROM nginx:alpine

COPY --from=build /app/build /usr/share/nginx/html

RUN rm /etc/nginx/conf.d/default.conf

COPY proxy/nginxssl.conf /etc/nginx/conf.d


EXPOSE 80
# start nginx 
CMD ["nginx", "-g", "daemon off;"]

But i don’t want this way.

Now i am seperating it’s like bellow.

Dockerfile.node


FROM node:14.1-alpine

WORKDIR /app
COPY . /app

ENV PATH /app/node_modules/.bin:$PATH

RUN yarn config delete proxy
RUN npm config rm proxy


# Satisfy node requirements
RUN npm config rm https-proxy
RUN npm install
RUN npm run build

and other one Dockerfile.proxy file

# nginx 
FROM nginx:alpine

COPY --from=build /app/build /usr/share/nginx/html

RUN rm /etc/nginx/conf.d/default.conf

COPY proxy/nginxssl.conf /etc/nginx/conf.d


EXPOSE 80
# start nginx 
CMD ["nginx", "-g", "daemon off;"]

You may noticed this line: COPY --from=build /app/build /usr/share/nginx/html in multi-stage, it is copying successfully but as i separated two file, they are not working.

is there anyone anyone how to copy two dockerfile data in two file.

This one is my docker compose

#the docker compose file version
version: "3.7"

services:
 
  react-prod:
   
    container_name: react-prod
    build:
      context: .
      dockerfile:
        Dockerfile.node
      
    ports:
      - "80:80"
      - "443:443"
  
  proxy:
    container_name: nginx-prod
    build:
      context: ./proxy
      dockerfile:
        Dockerfile.proxy
    ports:
      - "80:80"
      - "443:443"

Source: Docker Questions

LEAVE A COMMENT