0

I'm trying to dockerize my application. It consists of a .NET Core backend and an Angular frontend, set up like this:

  1. root folder

    • docker-compose
    • Dockerfile

      1. web subfolder (contains Angular frontend)
      2. api subfolder (contains .NET Core backend)

    I can successfully create a container using a docker-compose and Dockerfile. I can't figure out how to actually run the application in Docker. Normally when I want to run the application locally on my computer I do the 'dotnet run' command from the api folder using Powershell and then in another Powershell window I run the 'ng serve' command from the web folder. How would I run two shell commands from two different folders in either docker-compose or a Dockerfile?

I tried adding the two commands at the end of the Dockerfile like this:

RUN cd api && dotnet run api.csproj

RUN cd web && ng serve

Docker runs the first line but never gets to the next line. I'm guessing I have to issue commands from the docker-compose but I don't know how to go about it.

UPDATE: In response to splitting the application into two different containers, the two parts are dependent on each other. The backend has a symlink to the frontend. When the backend is initialized it checks to see if node is installed and the node_modules folder from the frontend exists, if it doesn't then an error occurs. In the docker container, I need to create the frontend first and install node then create the backend. I also figured to keep the file size down it made sense to keep everything in one container.

2
  • 1
    It seems to me you actually have two distinct applications. In this case, I would usually try to have one Dockerfile for each application. Is there a specific reason why you want to have both these applications running from a single Docker container? Commented Feb 16, 2020 at 20:48
  • The app is set up where the backend has a symlink to the frontend. I need to create the frontend first then the backend, otherwise the app throws an error when initialized. Commented Feb 17, 2020 at 14:08

1 Answer 1

1

You are using 'command1 && command2' which means run command2 if command1 exited with exit code 0, however command1 never exits.

In order to run 2 processes in one container you can follow this guide.

Note: A container in most cases is supposed to be one isolated process, as a result you should consider separating your application in two containers, one for the frontend and one for the backend.

Sign up to request clarification or add additional context in comments.

2 Comments

I did have the application separated into two containers at first but kept encountering problems. I couldn't figure out how to get the backend container to detect node and the node_modules folder in the frontend container.
I checked out the link you provided. I think the way to go is to create a Powershell script that will start two processes. Thanks for the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.