简体   繁体   English

Python 使用 AWS BAtch 执行脚本

[英]Python Script Execution with AWS BAtch

I created a simple docker container to run a python script from within the container:我创建了一个简单的 docker 容器以从容器内运行 python 脚本:

FROM python:3
WORKDIR /usr/src/app
COPY . .
CMD ["test.py"]
ENTRYPOINT ["python3"]

I build it, docker build -t hello-demo.我构建它, docker build -t hello-demo. and then run it docker run -it hello-demo test.py and I get my output.然后运行它docker run -it hello-demo test.py我得到我的 output。

But what I want to do is to be able to rerun this not on my laptop but using AWS Batch.但我想要做的是能够使用 AWS Batch 重新运行它,而不是在我的笔记本电脑上。 But I am not sure how to identify the container name Batch creates.但我不确定如何识别 Batch 创建的容器名称。 When I manually build the container I specify what I am calling it, but I am not sure how to call the correct container when running my docker run command.当我手动构建容器时,我指定了我对它的调用,但我不确定在运行 docker 运行命令时如何调用正确的容器。

Any thoughts?有什么想法吗? Or am I going about this wrong?还是我做错了? Thanks!谢谢! D

First, distinguish the Docker image from the Docker container.首先,区分 Docker 镜像和 Docker 容器。 You build the Docker image and the container is a running instance of the image (refer to the Docker overview for more details).您构建 Docker 映像,容器是该映像的运行实例(有关详细信息,请参阅Docker 概述)。 When you run the Docker image locally you specify what Docker image to run and also (optionally) the name of the container.当您在本地运行 Docker 图像时,您指定要运行的 Docker 图像以及(可选)容器的名称。

When using AWS Batch, you create a job definition which defines what Docker image it will use.使用 AWS Batch 时,您创建一个作业定义,定义它将使用的 Docker 图像。 Thus, the Docker image already has to exist in some registry, be it Docker Hub, ECR or any other registry.因此,Docker 图像必须已经存在于某些注册表中,无论是 Docker Hub、ECR 还是任何其他注册表。 You can also define other container properties like a command that will be run.您还可以定义其他容器属性,例如将要运行的命令。

To actually run the Batch job, you submit it to the queue using the job definition (which specifies the Docker image as stated above).要实际运行 Batch 作业,您可以使用作业定义(如上所述指定 Docker 图像) 将其提交到队列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM