使用Docker运行和集成Django后端和Angular前端

时间:2020-05-19 12:11:54

标签: docker docker-compose dockerfile

我已经创建了一个基于角度的前端和基于django rest框架的后端的应用程序。 我为他们两个都创建了一个映像,并且使用docker运行得很好。 av-app-multistage容器是有角度的容器,服务器是django后端。 enter image description here

要运行此应用程序,我必须分别启动它们。我如何创建某种脚本来自动执行此过程。这样,如果我运行有角容器,它将自动运行后端??

这是我的dockerfiles。 这是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

1 个答案:

答案 0 :(得分:0)

您可以在一个撰写文件中以堆栈形式启动它们。

结帐docker stack deploy命令

您还可以使用这两个服务编写一个compose文件,并且还可以通过某种方式编写它们,以使前端取决于后端。