Containerising Python command line application
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?
python docker pip setuptools
add a comment |
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?
python docker pip setuptools
3
write a Dockerfile ;-)
– Anna Jeanine
Nov 23 '18 at 15:31
Why not use PyInstaller?
– phd
Nov 23 '18 at 17:43
The official Docker tutorial on building and running custom images is extremely close to what you're asking for.
– David Maze
Nov 24 '18 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.
– Mikko Ohtamaa
Nov 24 '18 at 12:36
add a comment |
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?
python docker pip setuptools
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?
python docker pip setuptools
python docker pip setuptools
asked Nov 23 '18 at 15:29
Mikko OhtamaaMikko Ohtamaa
46.8k28164299
46.8k28164299
3
write a Dockerfile ;-)
– Anna Jeanine
Nov 23 '18 at 15:31
Why not use PyInstaller?
– phd
Nov 23 '18 at 17:43
The official Docker tutorial on building and running custom images is extremely close to what you're asking for.
– David Maze
Nov 24 '18 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.
– Mikko Ohtamaa
Nov 24 '18 at 12:36
add a comment |
3
write a Dockerfile ;-)
– Anna Jeanine
Nov 23 '18 at 15:31
Why not use PyInstaller?
– phd
Nov 23 '18 at 17:43
The official Docker tutorial on building and running custom images is extremely close to what you're asking for.
– David Maze
Nov 24 '18 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.
– Mikko Ohtamaa
Nov 24 '18 at 12:36
3
3
write a Dockerfile ;-)
– Anna Jeanine
Nov 23 '18 at 15:31
write a Dockerfile ;-)
– Anna Jeanine
Nov 23 '18 at 15:31
Why not use PyInstaller?
– phd
Nov 23 '18 at 17:43
Why not use PyInstaller?
– phd
Nov 23 '18 at 17:43
The official Docker tutorial on building and running custom images is extremely close to what you're asking for.
– David Maze
Nov 24 '18 at 3:02
The official Docker tutorial on building and running custom images is extremely close to what you're asking for.
– David Maze
Nov 24 '18 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.
– Mikko Ohtamaa
Nov 24 '18 at 12:36
@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.
– Mikko Ohtamaa
Nov 24 '18 at 12:36
add a comment |
1 Answer
1
active
oldest
votes
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>
Thank you. Your comment regarding "language specific best practices" is what I exactly look advise for. Instead of reinventing Python wheel.
– Mikko Ohtamaa
Nov 24 '18 at 12:40
1
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
– Farhad Farahi
Nov 24 '18 at 13:05
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.
– Mikko Ohtamaa
Nov 24 '18 at 13:09
For the future reference, here is my Dockerfile: github.com/TokenMarketNet/sto/blob/master/Dockerfile
– Mikko Ohtamaa
Nov 30 '18 at 12:04
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53449347%2fcontainerising-python-command-line-application%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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>
Thank you. Your comment regarding "language specific best practices" is what I exactly look advise for. Instead of reinventing Python wheel.
– Mikko Ohtamaa
Nov 24 '18 at 12:40
1
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
– Farhad Farahi
Nov 24 '18 at 13:05
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.
– Mikko Ohtamaa
Nov 24 '18 at 13:09
For the future reference, here is my Dockerfile: github.com/TokenMarketNet/sto/blob/master/Dockerfile
– Mikko Ohtamaa
Nov 30 '18 at 12:04
add a comment |
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>
Thank you. Your comment regarding "language specific best practices" is what I exactly look advise for. Instead of reinventing Python wheel.
– Mikko Ohtamaa
Nov 24 '18 at 12:40
1
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
– Farhad Farahi
Nov 24 '18 at 13:05
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.
– Mikko Ohtamaa
Nov 24 '18 at 13:09
For the future reference, here is my Dockerfile: github.com/TokenMarketNet/sto/blob/master/Dockerfile
– Mikko Ohtamaa
Nov 30 '18 at 12:04
add a comment |
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>
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>
answered Nov 23 '18 at 17:23
Farhad FarahiFarhad Farahi
14.1k33744
14.1k33744
Thank you. Your comment regarding "language specific best practices" is what I exactly look advise for. Instead of reinventing Python wheel.
– Mikko Ohtamaa
Nov 24 '18 at 12:40
1
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
– Farhad Farahi
Nov 24 '18 at 13:05
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.
– Mikko Ohtamaa
Nov 24 '18 at 13:09
For the future reference, here is my Dockerfile: github.com/TokenMarketNet/sto/blob/master/Dockerfile
– Mikko Ohtamaa
Nov 30 '18 at 12:04
add a comment |
Thank you. Your comment regarding "language specific best practices" is what I exactly look advise for. Instead of reinventing Python wheel.
– Mikko Ohtamaa
Nov 24 '18 at 12:40
1
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
– Farhad Farahi
Nov 24 '18 at 13:05
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.
– Mikko Ohtamaa
Nov 24 '18 at 13:09
For the future reference, here is my Dockerfile: github.com/TokenMarketNet/sto/blob/master/Dockerfile
– Mikko Ohtamaa
Nov 30 '18 at 12:04
Thank you. Your comment regarding "language specific best practices" is what I exactly look advise for. Instead of reinventing Python wheel.
– Mikko Ohtamaa
Nov 24 '18 at 12:40
Thank you. Your comment regarding "language specific best practices" is what I exactly look advise for. Instead of reinventing Python wheel.
– Mikko Ohtamaa
Nov 24 '18 at 12:40
1
1
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
– Farhad Farahi
Nov 24 '18 at 13:05
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
– Farhad Farahi
Nov 24 '18 at 13:05
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.
– Mikko Ohtamaa
Nov 24 '18 at 13:09
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.
– Mikko Ohtamaa
Nov 24 '18 at 13:09
For the future reference, here is my Dockerfile: github.com/TokenMarketNet/sto/blob/master/Dockerfile
– Mikko Ohtamaa
Nov 30 '18 at 12:04
For the future reference, here is my Dockerfile: github.com/TokenMarketNet/sto/blob/master/Dockerfile
– Mikko Ohtamaa
Nov 30 '18 at 12:04
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53449347%2fcontainerising-python-command-line-application%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
write a Dockerfile ;-)
– Anna Jeanine
Nov 23 '18 at 15:31
Why not use PyInstaller?
– phd
Nov 23 '18 at 17:43
The official Docker tutorial on building and running custom images is extremely close to what you're asking for.
– David Maze
Nov 24 '18 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.
– Mikko Ohtamaa
Nov 24 '18 at 12:36