我可以将传递给 docker 图像的参数映射到 python 中的环境变量吗?
can i map parameters passed to a docker image to env variables in python?
我有一个 python 应用程序,我正在为该应用程序创建 docker 图片。示例(下面的 docker 文件)。我想 运行 aws ec2 或 aws 批处理作业中的容器。我可以在 运行 宁 docker 容器时传递一些参数,以便它可以传递到我的 python 应用程序并且该应用程序可以在 运行 时间使用这些值。是否可以在启动批处理作业时传递参数,可以将其映射到我的应用程序中定义的一些环境变量?
FROM python:3.7
ADD test.py /
RUN pip install ...
CMD [ "python3", "./test.py" ]
Is it possible to pass the argument as when starting a batch job, that
can be mapped to some env variables defined in my app?
什么时候可以pass environment variable to AWS batch job为什么需要用参数映射应用程序环境变量?
您可以在 Job Definitions 中设置环境变量并在 python 应用程序中使用这些变量。
以下配置类似于docker run -it -e BATCH_FILE_S3_URL="s3://my-batch-scripts/myjob.sh"
在作业定义中设置环境变量
{
"containerProperties": {
.
.
.
"environment": [
{
"name": "BATCH_FILE_S3_URL",
"value": "s3://my-batch-scripts/myjob.sh"
},
{
"name": "BATCH_FILE_TYPE",
"value": "script"
}
]
}
在python申请中,
S3_URL=os.getenv('BATCH_FILE_S3_URL')
# S3_URL will be `s3://my-batch-scripts/myjob.sh`
我有一个 python 应用程序,我正在为该应用程序创建 docker 图片。示例(下面的 docker 文件)。我想 运行 aws ec2 或 aws 批处理作业中的容器。我可以在 运行 宁 docker 容器时传递一些参数,以便它可以传递到我的 python 应用程序并且该应用程序可以在 运行 时间使用这些值。是否可以在启动批处理作业时传递参数,可以将其映射到我的应用程序中定义的一些环境变量?
FROM python:3.7
ADD test.py /
RUN pip install ...
CMD [ "python3", "./test.py" ]
Is it possible to pass the argument as when starting a batch job, that can be mapped to some env variables defined in my app?
什么时候可以pass environment variable to AWS batch job为什么需要用参数映射应用程序环境变量?
您可以在 Job Definitions 中设置环境变量并在 python 应用程序中使用这些变量。
以下配置类似于docker run -it -e BATCH_FILE_S3_URL="s3://my-batch-scripts/myjob.sh"
在作业定义中设置环境变量
{
"containerProperties": {
.
.
.
"environment": [
{
"name": "BATCH_FILE_S3_URL",
"value": "s3://my-batch-scripts/myjob.sh"
},
{
"name": "BATCH_FILE_TYPE",
"value": "script"
}
]
}
在python申请中,
S3_URL=os.getenv('BATCH_FILE_S3_URL')
# S3_URL will be `s3://my-batch-scripts/myjob.sh`