kube 1

Build docker image
cloud-computing

~


내 리액트앱 nginx로 서빙하는 도커이미지 만들기

FROM nginx

# nginx의 default.conf를 삭제
RUN rm /etc/nginx/conf.d/default.conf

# host pc의 nginx.conf를 아래 경로에 복사
COPY ./nginx.config /etc/nginx/conf.d

# 80 포트 오픈
EXPOSE 80

# container 실행 시 자동으로 실행할 command. nginx 시작함
CMD nginx -g 'daemon off;'


multi stage

# Build Stage Start
# Specify a base image
FROM node:alpine as builder

# Specify a working directory
WORKDIR '/app'

# Copy the dependencies file
COPY package.json .

# Install dependencies
RUN npm install

# Copy remaining files
COPY . .

# Build the project for production
RUN npm run build

# Run Stage Start
FROM nginx

# Copy production build files from builder phase to nginx
COPY --from=builder /app/build /usr/share/nginx/html


221127 스터디

# Dockerfile.apiserver

FROM node

WORKDIR /usr/src/app
COPY package*.json /usr/src/app/
ENV NODE_OPTIONS="--openssl-legacy-provider"

RUN npm install
COPY backend /usr/src/app/backend/

EXPOSE 3777

ENTRYPOINT ["node", "/usr/src/app/backend/server.js"]
# Dockerfile.front

FROM node as builder

RUN mkdir /usr/src/app
WORKDIR /usr/src/app
ENV NODE_OPTIONS="--openssl-legacy-provider"
COPY package*.json /usr/src/app/
RUN npm install

COPY . /usr/src/app
RUN npm run build

FROM nginx

WORKDIR /usr/share/nginx/html
RUN rm -rf /etc/nginx/conf.d
COPY conf /etc/nginx/conf.d/

COPY --from=builder /usr/src/app/build/ .

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
# conf/default.conf

server {
  listen 80;
  # listen [::]:80;

  location / {
    root   /usr/share/nginx/html;
    index  index.html index.htm;
    try_files $uri $uri/ /index.html;
  }

  location /api {
    proxy_pass http://todo-api:3777;
  }

  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
    root   /usr/share/nginx/html;
  }
}
# docker-compose.yml

version: '3'
services:
  todo-api:
    container_name: todo-api
    image: todo-api:latest
    networks:
     - default

  todo-app:
    container_name: todo-app
    image: todo-app:latest
    networks:
     - default
    ports:
     - 80:80
    links:
     - todo-api

networks:
  default:
    external:
      name: todoapp
$ docker-compose up -d
$ docker-compose down