Reputation: 2358
I'm trying to dockerize my application. It consists of a .NET Core backend and an Angular frontend, set up like this:
root folder
Dockerfile
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.
Upvotes: 0
Views: 1006
Reputation: 1450
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.
Upvotes: 1