Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using docker-compose in azure app service

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"

like image 581
user6680 Avatar asked Feb 19 '20 15:02

user6680


People also ask

Does Azure App Service use Docker?

Azure App Service uses the Docker container technology to host both built-in images and custom images.

How do I run a Docker image in Azure App Service?

In Docker Explorer, navigate to your image under Registries, right-click on the tag, and select Deploy Image To Azure App Service.... When prompted, provide the values for the App Service. New web app name: The name must be unique across Azure. Resource group: Select an existing resource group or create a new one.


2 Answers

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.

like image 108
Charles Xu Avatar answered Oct 22 '22 06:10

Charles Xu


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

like image 25
VonC Avatar answered Oct 22 '22 05:10

VonC