Примеры работы с Docker Compose


Ответы

Файл Dockerfile

FROM node:12 as app

CMD [ "npm", "run", "start"]

WORKDIR /app
RUN npm -g i npm
COPY ./package*.json /app/
RUN npm ci
COPY ./ /app
RUN npm run build src

FROM nginx as nginx
COPY ./vhost.conf /etc/nginx/conf.d/default.conf
COPY --from=app /app/src/static /static/

Файл docker-compose.yml

version: '3.7'

services:
  nginx:
    build:
      context: ../
      dockerfile: docker/Dockerfile
      target: nginx
    restart: always
    links:
      - app
    ports:
      - "80:80"

  app:
    build:
      context: ../
      dockerfile: docker/Dockerfile
      target: app
    restart: always

Сборка

docker-compose -f docker/docker-compose.yml build

Запуск

docker-compose -f docker/docker-compose.yml up