5
votes

I got my mean stack code working in a docker-compose configuration. If I run docker-compose up on my pc, then I can login to my app successfully on localhost If go to app service and click on docker-compose preview option and upload my docker-compose.yml file. After deploying it, when I click on the URL for the app I get application error and I'm not sure why. Perhaps I have to change something in my files to make it work in different environment? I appreciate any help with this!

I read somewhere that I don't have to provide username,password, or url details if using ACR in same subscription, which it is. So if that's the case, then authentication isn't the issue.

The frontend docker image and backend docker image are located in the azure container registry. I'm pointing to the registry when I setup docker in app service The docker logs from azure say

2020-02-19 15:08:20.257 INFO  - Starting multi-container app, configuration = 


2020-02-19 15:08:22.806 ERROR - Pull image threw Exception: Object reference not set to an instance of an object.
2020-02-19 15:08:22.806 ERROR - Pulling docker image  failed:
2020-02-19 15:08:22.806 ERROR - Image pull failed: Verify docker image configuration and credentials (if using private repository)
2020-02-19 15:08:22.806 ERROR - multi-container unit was not started successfully
2020-02-19 15:08:22.831 INFO  - Container logs from testinggc_backend_0_250edca0 = 
2020-02-19 15:08:28.902 INFO  - Stoping site testinggc because it failed during startup.
2020-02-19 15:08:30.129 INFO  - Starting multi-container app, configuration = 


frontend Dockerfile

FROM node

MAINTAINER Phil

WORKDIR /src

COPY . .

RUN npm install

RUN npm install -g @angular/cli

EXPOSE 4200

CMD ng serve --host 0.0.0.0 --port 4200

backend Dockerfile

FROM node:10.16.3

MAINTAINER Phil

WORKDIR /src

COPY . /src

RUN npm install

RUN npm install -g nodemon

EXPOSE 3000

CMD ["npm", "run", "start"]

docker-compose.yml


version: '3'
services:
    backend:
        build: ./backend
        ports:
            - "3000:3000"
    frontend:
        build: ./frontend
        ports:
            - "4200:80"

2

2 Answers

7
votes

For this issue, the problem is the property build of the docker-compose that does not support in Azure App Service. You can get more details about the support options in Docker Compose options.

So the solution for you is to create the image locally yourself and then push them to a docker registry, for example, the Azure Container Registry. Finally, you need to change the build into image. Then deploy it to Azure App Service and it would work fine.

3
votes

Another approach would be to use the more recent (Oct. 2020) compose-cli, which is made to run both locally, and in the context of a Microsoft ACI (Azure Container Instance).

Example: "Deploying a Minecraft Docker Server to the cloud" from Guillaume Tardif (Senior Software Engineer @ Docker)

The command to start this locally is now much simpler:

$ docker-compose --project-name mc up

And to deploy to ACI, still using the ACI context I created previously:

$ docker compose --project-name mc2 up 

See also "How To Deploy Containers to Azure ACI using Docker CLI and Compose" from Peter McKee (Coding Adventures.io).

You can easily create your ACI-complient context:

docker context create aci myaci
docker-compose push
docker context use myaci
docker compose up

Plus, "VSCode Docker extension can now run containers in Azure Container Instances" from Mike Morton (Senior Program Manager - Microsoft - Visual Studio)

https://cloudblogs.microsoft.com/uploads/prod/sites/37/2020/07/CreateContextPlusActions.gif