【问题标题】:Mount an Azure file share in Dockerfile locally在本地装载 Dockerfile 中的 Azure 文件共享
【发布时间】:2021-09-23 01:00:39
【问题描述】:

您好,我在本地运行容器时尝试使用 Azure 文件共享作为卷。我在 azure 中创建了 FilShare。现在,当我在本地运行 docker-file 时,我想挂载 azure 文件共享。如果我们使用应用服务部署 webapp,则有路径映射选项。我想在当地试试。下面是我的 dockerfile。

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /app
ENV ASPNETCORE_URLS=http://+:80  
EXPOSE 80
ARG PAT
# Set environment variables
COPY MountVolume.sln ./
COPY MountVolume/*.csproj ./MountVolume/
RUN dotnet restore
COPY MountVolume/. ./MountVolume/
RUN dotnet publish -c Release -o out
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS runtime
WORKDIR /app
COPY --from=build /app/out ./
ENTRYPOINT ["dotnet", "MountVolume.dll"]

下面是 docker-compose 文件

version: "3.9"
services:
  mountvolume:    
    container_name: mountvolume
    build:      
      context: .
      dockerfile: ./Dockerfile   
    ports:
      - "8080:80"

这里我想将挂载点指定为 Azure 文件共享。我找不到任何东西,比如如何传递文件共享名称或连接字符串等

我有以下命令要运行

docker run -it -p 8080:80 --name mountvolume mountvolume

在我的应用程序中,我设置了 SDK 以从卷中获取文件。现在我唯一坚持的一点是如何在此处安装 azure 文件共享。有人可以帮我完成这个吗?任何帮助,将不胜感激。谢谢

【问题讨论】:

    标签: azure docker asp.net-core docker-volume storage-file-share


    【解决方案1】:

    在 Azure 容器实例中装载 Azure 文件共享

    您可以部署使用存储在卷中的持久数据的容器或 Compose 应用程序。 Azure 文件共享可用于支持 ACI 容器的卷。 使用具有存储帐户名称 mystorageaccount 和文件共享名称 myfileshare 的现有 Azure 文件共享,您可以在部署运行命令中指定卷,如下所示:

    $ docker run -v mystorageaccount/myfileshare/aci/logs/ myimage
    

    运行时容器将在 /aci/logs/ 中看到文件共享内容。 在 Compose 应用程序中,卷规范必须在 Compose 文件中使用以下语法:

    apiVersion: '2019-12-01'
    location: eastus
    name: file-share-demo
    properties:
      containers:
      - name: hellofiles
        properties:
          environmentVariables: []
          image: mcr.microsoft.com/azuredocs/aci-hellofiles
          ports:
          - port: 80
          resources:
            requests:
              cpu: 1.0
              memoryInGB: 1.5
          volumeMounts:
          - mountPath: /aci/logs/
            name: filesharevolume
      osType: Linux
      restartPolicy: Always
      ipAddress:
        type: Public
        ports:
          - port: 80
        dnsNameLabel: aci-demo
      volumes:
      - name: filesharevolume
        azureFile:
          sharename: myfileshare
          storageAccountName: mystorageaccount 
          storageAccountKey: <Storage account key>
    tags: {}
    type: Microsoft.ContainerInstance/containerGroups
    

    您可以参考Using Azure file share as volumeMount an Azure file share in Azure Container Instancesmount azure file share to web app for linux containers with docker-composeHow to mount docker volume in Azure Web App for containers?

    【讨论】:

      猜你喜欢
      • 2021-12-08
      • 2016-03-13
      • 1970-01-01
      • 1970-01-01
      • 2020-12-10
      • 2021-08-15
      • 2018-04-15
      • 2022-06-16
      • 2022-06-30
      相关资源
      最近更新 更多