2

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?

4
  • 3
    write a Dockerfile ;-) Commented Nov 23, 2018 at 15:31
  • Why not use PyInstaller? Commented Nov 23, 2018 at 17:43
  • The official Docker tutorial on building and running custom images is extremely close to what you're asking for. Commented Nov 24, 2018 at 3:02
  • @phd Why not indeed... with Docker you need to build and distribute only one image. PyInstaller would still need to generate different binaries for every platform. Commented Nov 24, 2018 at 12:36

1 Answer 1

4

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>
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you. Your comment regarding "language specific best practices" is what I exactly look advise for. Instead of reinventing Python wheel.
The general rule of thumb is to use alpine image and only install required dependencies, delete the apk cache but you can find various sources online for python
Thank you once again. Also you hit the nail on the head whenyou say that you can find various sources online - the sources are "various". There are good, bad and ugly tutorials out there and that 's why I result to the professional advise on StackOverflow as here people with insight can comment the matter.
For the future reference, here is my Dockerfile: github.com/TokenMarketNet/sto/blob/master/Dockerfile

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.