【问题标题】:Mounting Azure Blob Storage in Docker File在 Docker 文件中挂载 Azure Blob 存储
【发布时间】:2020-06-29 15:36:06
【问题描述】:

我正在 Azure Devops 中创建一个 dockerfile,并尝试将 Azure Blob 存储容器(包含文件)挂载到 dockerfile 中。我知道微软有关于卷的帮助,但它们是 yaml 格式,这不适合我,因为我正在使用 Azure Devops Pipeline 构建我的图像。我真的很感谢你的帮助。提前致谢

目前我的代码是这样的

FROM ubuntu:18.04

# Update the repository sources list
RUN apt-get update
FROM python:3.7.5
RUN apt-get update
RUN DEBIAN_FRONTEND=noninteractive 
RUN apt-get install -y  build-essential python3-pip python3-dev postgresql-11 postgresql-contrib ufw sudo libssl-dev libffi-dev 
RUN apt-get install -y  libldap2-dev libsasl2-dev ldap-utils 
RUN apt-get install -y  systemd vim

# Install ODBC driver 17
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update -y
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql17 mssql-tools unixodbc-dev redis-server rabbitmq-server

# Install python libraries
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code
RUN pip install --upgrade pip && \
    pip install -r requirements.txt

RUN mkdir /home/workspace
WORKDIR /home/workspace

COPY ./ /home/workspace

# Mount
## *** REQUIRE HELP HERE ***##


RUN service postgresql start
CMD ["python", "home/workspace/python manage.py runserver 0:8000"]

【问题讨论】:

  • 你知道怎么做吗?
  • 挂载是指挂载卷吗?因为这是在运行时完成的,而不是构建时。你到底想做什么?
  • RUN service postgresql start 暗示你想要一个 postgres 服务一个在同一个容器中运行的 python 服务。不幸的是,这不是它的工作方式。您的 postgres 服务应该是一个单独的容器
  • @risail Evelyn,请问您在哪里部署您的应用程序?到 ACI,到应用服务?
  • @jccampanero 那篇文章实际上是我最终做到的。

标签: azure docker yaml dockerfile azure-blob-storage


【解决方案1】:

您的容器将在其中部署的最终运行时可能是相关的,因为 Azure 会根据您实际部署它的位置为您提供或不提供一些选项。

请考虑this question,我在其中提供了一些帮助:如您所见,如果您使用 docker compose 和应用服务,Azure 为您提供了在容器中安装 Azure 文件或 Blob 存储的机会。

根据您的 cmets,您正在使用 AKS。 AKS 和 Kubernetes 是一个非常具体的用例。与其尝试使用 AZ CLI 将内容从存储帐户复制到容器,不如利用 Kubernetes 提供的机制并尝试使用卷挂载。

请考虑阅读this excellent article。作者在两篇配套文章中公开了一个与您的非常相似的用例,但使用的是 SQLite。

基本上,按照上述帖子中提供的指导,首先,使用 Azure 存储连接数据创建一个 Kubernetes Secret。您需要提供有关您的存储帐户名称和访问密钥的值的信息。 yaml 配置文件将类似于:

apiVersion: v1
kind: Secret
metadata:
  name: your-secret
  namespace: your-namespace
type: Opaque
data:
  azurestorageaccountname: Base64_Encoded_Value_Here
  azurestorageaccountkey: Base64_Encoded_Value_Here

然后,创建 Kubernetes 部署并定义适当的卷挂载。例如,假设您的 Azure 存储文件共享的名称是 your-file-share-name

apiVersion: apps/v1
kind: Deployment
metadata:
  name: deployment-azurestorage-test
  namespace: your-namespace
spec:  
  selector:
      matchLabels:
        app: your-app
  template:
    metadata:
      labels:
        app: your-app
    spec:
      containers:
      - name: your-app
        image: your-registry.azurecr.io/your-app:latest
        volumeMounts:
        - name: azurefileshare
          mountPath: /postgre-require-dmount-path
      imagePullSecrets:
      - name: your-pull-secret-if-you-have-one       
      volumes:
      - name: azurefileshare
        azureFile:
          secretName: your-secret
          shareName: your-file-share-name
          readOnly: false

部署中需要注意的重要事项是 volumeMounts,用于指定文件共享在容器内的挂载路径,适合您的 PostgreSQL 部署,以及 volumes ,带有 azureFile 条目,包含有关先前创建的机密名称和实际 Azure 存储文件共享名称的信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-20
    • 2017-11-26
    • 1970-01-01
    • 2021-12-08
    • 2021-06-17
    • 2021-07-09
    相关资源
    最近更新 更多