0
votes

I'm building an app with separated frontend (Angular 4 - from Angular CLI) and backend app (Asp.Net Core Preview 2.0).

I try to use Docker. Everything works fine but I need to manually publish backend app to ${source:-obj/Docker/publish}. Is it to possible to automate it? For example put the publish code to Dockerfile or docker compose ?

Here's my Dockerfile of my backend app:

FROM microsoft/aspnetcore:2.0
ARG source
WORKDIR /app
EXPOSE 80
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "Api.dll"]

Here's my Dockerfile of my frontend app:

FROM node:7
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app
RUN npm install
COPY . /usr/src/app
EXPOSE 4200
CMD ["npm", "start"]

Here's my docker-compose:

version: '3.3'

services:
  api:
    image: api
    build:
      context: ./Api
      dockerfile: Dockerfile
  frontend:
    image: frontend
    build: 
      context: ./FrontEnd
      dockerfile: Dockerfile

Thanks in advance.

2

2 Answers

0
votes

You can combine the content of the DockerFile of both front end and backend as follows:

FROM node:7
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app
RUN npm install
COPY . /usr/src/app
EXPOSE 4200

FROM microsoft/aspnetcore:2.0
ARG source
WORKDIR /app
EXPOSE 80
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "Api.dll"]
CMD ["npm", "start"]

Then build the single image as :

docker build -t "frontendbackend" -f Dockerfile .
-1
votes

If you use Visual Studio. Add docker support for your backend project. Then set docker-compose project as a start up project. When you build solution it will run docker compose on docker-compose.ci.build.yml that will do all job for you. If you want to publish images then change build to release and build again.