在 azure 应用服务中使用 docker-compose

use*_*680 5 azure node.js docker docker-compose azure-web-app-service

我让我的平均堆栈代码在 docker-compose 配置中工作。如果我docker-compose up在我的电脑上运行,那么我可以成功登录到我的应用程序localhost如果转到应用程序服务并单击 docker-compose 预览选项并上传我的 docker-compose.yml 文件。部署后,当我单击该应用程序的 URL 时,出现应用程序错误,但不知道为什么。也许我必须更改文件中的某些内容才能使其在不同的环境中工作?我感谢任何帮助!

我在某处读到,如果在同一订阅中使用 ACR,则不必提供用户名、密码或 URL 详细信息,确实如此。因此,如果是这种情况,则身份验证不是问题。

前端 docker 镜像和后端 docker 镜像位于 azure 容器注册表中。当我在应用服务中设置 docker 时,我指向注册表 来自 azure 的 docker 日志说

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 = 


Run Code Online (Sandbox Code Playgroud)

前端 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
Run Code Online (Sandbox Code Playgroud)

后端 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"]
Run Code Online (Sandbox Code Playgroud)

docker-compose.yml


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

Run Code Online (Sandbox Code Playgroud)

Cha*_* Xu 7

对于这个问题,问题在于buildAzure App Service中不支持的docker-compose的属性。您可以在Docker Compose options 中获取有关支持选项的更多详细信息。

因此,您的解决方案是自己在本地创建映像,然后将它们推送到 docker 注册表,例如 Azure 容器注册表。最后,你需要改变buildimage。然后将其部署到 Azure 应用服务,它会正常工作。


Von*_*onC 5

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
Run Code Online (Sandbox Code Playgroud)

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

$ docker compose --project-name mc2 up 
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

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

  • 但是 ACI != AppService 对吗? (5认同)