Containerising Python command line application

Deadly 提交于 2019-12-24 06:05:35

问题


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

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.

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?


回答1:


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>


来源:https://stackoverflow.com/questions/53449347/containerising-python-command-line-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!