简体   繁体   English

包含Python命令行应用程序

[英]Containerising Python command line application

I have created a Python command line application that is available through PyPi / pip install . 我已经创建了一个可以通过PyPi / pip install获得的Python命令行应用程序。

The application has native dependencies. 该应用程序具有本机依赖性。

To make the installation less painful for Windows users I would like to create a Dockerised version out of this command line application. 为了减轻Windows用户的安装需求,我想从这个命令行应用程序中创建一个Dockerised版本。

What are the steps to convert setup.py with an entry point and requirements.txt to a command line application easily? 将带有入口点和requirements.txt的setup.py轻松转换为命令行应用程序的步骤是什么? Are there any tooling around this, or should I just write Dockerfile by hand? 有没有任何工具,或者我应该手动编写Dockerfile

Well, You have to create a Dockerfile and build an image off of it. 好吧,你必须创建一个Dockerfile并从中构建一个图像。 There are best practices regarding the docker image creation that you need to apply. 有关您需要应用的docker图像创建的最佳实践。 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>

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

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