Containerising Python command line application

2019-08-10 21:02发布

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条回答
Melony?
2楼-- · 2019-08-10 21:44

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>
查看更多
登录 后发表回答