【问题标题】:Using docker-compose in azure app service在 Azure 应用服务中使用 docker-compose
【发布时间】:2020-11-14 01:27:08
【问题描述】:

我的平均堆栈代码在 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 = 


前端 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

后端 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"

【问题讨论】:

    标签: node.js azure docker docker-compose azure-web-app-service


    【解决方案1】:

    对于这个问题,问题出在 Azure 应用服务中不支持的 docker-compose 的属性build。您可以在Docker Compose options 中获取有关支持选项的更多详细信息。

    因此,您的解决方案是自己在本地创建映像,然后将它们推送到 docker 注册表,例如 Azure 容器注册表。最后,您需要将build 更改为image。然后将其部署到 Azure App Service 就可以正常工作了。

    【讨论】:

    • 感谢您指出这一点。我从build 更改为image,但现在我得到一个身份验证错误,我不明白,因为我在应用服务中选择docker-compose 选项后指向注册表。错误:pastebin.com/NmVwCRRV
    • @user6680 当你创建镜像并推送到注册表时,我不知道你使用的是哪个注册表,但是如果注册表不是公共的,那么你需要添加凭据作为环境变量为注册表。查看变量here
    【解决方案2】:

    另一种方法是使用more recent(2020 年 10 月)compose-cli,它既可以在本地运行,也可以在 Microsoft ACI (Azure Container Instance) 的上下文中运行。

    示例:“Deploying a Minecraft Docker Server to the cloud”来自Guillaume Tardif(高级软件工程师@Docker)

    在本地启动它的命令现在更简单了:

    $ docker-compose --project-name mc up
    

    要部署到 ACI,仍然使用我之前创建的 ACI 上下文:

    $ docker compose --project-name mc2 up 
    

    另请参见Peter McKee (Coding Adventures.io) 中的“How To Deploy Containers to Azure ACI using Docker CLI and Compose”。

    您可以轻松创建符合 ACI 的上下文:

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

    另外,来自Mike Morton(高级项目经理 - Microsoft - Visual Studio)的“VSCode Docker extension can now run containers in Azure Container Instances

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-08
    • 1970-01-01
    • 2021-10-26
    • 1970-01-01
    • 2019-04-12
    • 2020-02-18
    • 1970-01-01
    • 2016-11-21
    相关资源
    最近更新 更多