容器化Python命令行应用程序 [英] Containerising Python command line application

查看:97
本文介绍了容器化Python命令行应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Python命令行应用程序,可通过PyPi/pip install使用.

I have created a Python command line application that is available through PyPi / pip install.

该应用程序具有本机依赖性.

The application has native dependencies.

为了减轻Windows用户的安装负担,我想在此命令行应用程序之外创建一个Dockerized版本.

To make the installation less painful for Windows users I would like to create a Dockerised version out of this command line application.

将带有入口点和Requirements.txt的setup.py轻松转换为命令行应用程序有哪些步骤?周围是否有任何工具,还是我应该手工编写Dockerfile?

What are the steps to convert setup.py with an entry point and requirements.txt to a command line application easily? Are there any tooling around this, or should I just write Dockerfile by hand?

推荐答案

好,您必须创建一个Dockerfile并从中构建映像.您需要应用有关创建Docker映像的最佳实践.还有针对特定语言的最佳做法.

Well, You have to create a Dockerfile and build an image off of it. There are best practices regarding the docker image creation that you need to apply. There are also language specific best practices.

只是给您一些有关该过程的想法:

Just to give you some ideas about the process:

FROM python:3.7.1-alpine3.8 #base image
ADD . /myapp # add project files
WORKDIR /myapp
RUN apk add dep1 dep2 #put your dependency packages here
RUN pip-3.7 install -r requirements.txt #install pip packages
RUN pip-3.7 install .
CMD myapp -h

现在构建映像并将其推送到一些公共注册表:

Now build image and push it to some public registry:

sudo docker build -t <yourusername>/myapp:0.1 .

用户可以仅提取图像并使用它:

users can just pull image and use it:

sudo docker run -it myapp:0.1 myapp.py <switches/arguments>

这篇关于容器化Python命令行应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆