在 Docker 文件中挂载 Azure Blob 存储

Eve*_*Omo 7 yaml azure docker 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"]

Run Code Online (Sandbox Code Playgroud)

jcc*_*ero 2

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

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

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

请考虑阅读这篇优秀的文章。作者在两篇同伴文章中公开了一个与您的非常相似的用例,但使用的是 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
Run Code Online (Sandbox Code Playgroud)

然后,创建 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
Run Code Online (Sandbox Code Playgroud)

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