【问题标题】:Running and integrating Django backend and Angular Frontend using docker使用 docker 运行和集成 Django 后端和 Angular 前端
【发布时间】:2020-05-19 21:03:41
【问题描述】:

我创建了一个带有 Angular 前端和基于 django rest 框架的后端的应用程序。 我已经为它们创建了一个图像,并且它们使用 docker 运行良好。 av-app-multistage 容器是 angular 容器,服务器是 django 后端。

要运行这个应用程序,我必须单独启动它们。我怎样才能创建某种脚本来自动化这个过程。这样如果我运行 angular 容器,它会自动运行后端??

这是我的 dockerfile。 这是 django 的 docker 文件

FROM python:3.6

# The enviroment variable ensures that the python output is set straight
# to the terminal with out buffering it first
ENV PYTHONUNBUFFERED 1

# create root directory for our project in the container
RUN mkdir /app_service

# Set the working directory to /music_service
WORKDIR /app_service

# Copy the current directory contents into the container at /music_service
ADD . /app_service/

# Install any needed packages specified in requirements.txt
RUN pip install -r requirements.txt

这是 django 的 docker compose 文件

version: '3'

services:
  web:
    build: .
    command: bash -c "python manage.py makemigrations && python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
    container_name: app_service
    volumes:
      - .:/app_service
    ports:
      - "8000:8000"

这是 Angular 的 docker 文件

FROM node:10.16-alpine AS build
WORKDIR /usr/src/app
COPY package.json ./
RUN npm install
COPY . .
RUN npm run build
### STAGE 2: Run ###
FROM nginx:1.17.1-alpine
COPY --from=build /usr/src/app/dist/movie-info-service /usr/share/nginx/html

【问题讨论】:

    标签: docker docker-compose dockerfile


    【解决方案1】:

    您可以在单个撰写文件中将它们作为堆栈启动。

    结帐docker stack deploy 命令

    您还可以使用这 2 个服务编写 compose 文件,您还可以将它们编写成前端依赖于后端的方式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-30
      • 2020-03-19
      • 2023-03-11
      • 2021-04-10
      • 1970-01-01
      • 1970-01-01
      • 2020-12-05
      相关资源
      最近更新 更多