azure - 在 Docker 文件中挂载 Azure Blob 存储

标签 azure docker yaml dockerfile azure-blob-storage

我正在 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"]

最佳答案

部署容器的最终运行时可能是相关的,因为 Azure 是否提供一些选项取决于您实际部署的位置。

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

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

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

基本上,按照上述帖子中提供的指导,首先使用 Azure 存储连接数据创建 Kubernetes Secret。您需要提供有关存储帐户名称和访问 key 之一的值的信息。 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 部署,以及,包含 azureFile 条目,其中包含有关之前创建的 secret 名称以及实际 Azure 存储文件共享的名称的信息。

关于azure - 在 Docker 文件中挂载 Azure Blob 存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60741286/

相关文章:

azure - 如何从多个Azure服务中删除标签?

node.js - Docker - 无法解析 '/usr/src/app/src' 中的 Node 模块

ansible - 将列表中的每个项目与字符串匹配

python - 404 来自谷歌应用引擎 django 应用程序上的 cron 作业

django - aadsts50011 : the reply url specified in the request does not match the reply urls configured for the application: 'App id' . 本地主机配置

azure - 获取 Azure 上的 Get-AzResource 返回的对象的属性

docker - GitLab CI Runner 无法提取私有(private) Docker 镜像 w。 "no basic auth credentials"但它通过 SSH 工作

node.js - docker-compose 不会覆盖使用启动命令的命令

yaml - 将列表包装在多行 yaml 上

node.js - 为什么这个Azure时间触发功能不会失败?