Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The size of the Python image - why 900MB? #30

Closed
Kentoseth opened this issue Jan 12, 2015 · 6 comments
Closed

The size of the Python image - why 900MB? #30

Kentoseth opened this issue Jan 12, 2015 · 6 comments

Comments

@Kentoseth
Copy link

I've just been reading up on Docker.

I like how it can containerize the entire app of each specific stack, but I don't understand why the Python image to install Docker is 900MB.

From this:

https://registry.hub.docker.com/_/python/

Some people have complained about the size.

What I would like to know is what that 900MB is made up of? Is it an OS + your engine + hundreds of C dependencies? Is it a virtualized OS only? Is it 900MB of everything in Python?

Are you basically installing a 'light' virtualized Debian OS to run Python?

If yes, I think you would be lying on this page:

https://www.docker.com/whatisdocker/

By not specifying that under certain conditions, the "Docker Engine" is coupled with an OS.

Some clarification on this will be much appreciated.

@tianon
Copy link
Member

tianon commented Jan 12, 2015

The base tags are engineered so that almost any arbitrary thing will pip install successfully (such that the python:onbuild images can be almost completely automatic and your entire Dockerfile to get started quickly with Docker can be as easy as FROM python:3-onbuild, for example).

If you check out the slim variants, they are much smaller, and geared more towards folks who actually know what they're doing and prefer to install exactly the dependencies they need.

@Kentoseth
Copy link
Author

@tianon :

Isn't this bad security practice though (for the 900MB base)?

There's tons of packages in PyPi and they have a lot of C dependencies also. Not all of them are maintained equally and if there is even just 1 C dependency that has an unmonitored security risk, it compromises the entire container.

In terms of using the slim variant, when attempting to install a C dependency, is it done the way it normally would on a Debian/Ubuntu box with sudo apt ... ?

I don't mind sharing some instructions for using the slim option as the "better" way to manage a Python container, but I can't seem to find the instructions for installing it (first time using Docker).

@yosifkit
Copy link
Member

Yeah it is just debian in the container so make a dockerfile similar to this would be the way:

FROM python:3-slim
RUN apt-get update \
    && apt-get install -y packageA packageB etc
COPY my-code /usr/src/my-app
CMD ["/usr/src/my-app/main.py"]

@Kentoseth
Copy link
Author

Thank you @yosifkit && @tianon for the help so far.

Apart from pre-installing the packages from the Dockerfile in the initial setup, can things also be installed within the container "on the fly"?

Eg. Let's say I am currently building an arbitrary photo-sharing app. I've setup my web-stack for all the Python-based tools I need. Now, I want to do some stuff to photos using the Python Imaging Library, known as PIL (it has C dependencies).

Can I (whilst working in my container), run:

sudo apt-get install x-file

to install the x-file package within the same container, or do I need to pre-plan and put everything into the Dockerfile first?

@yosifkit
Copy link
Member

You don't have to pre-plan everything. You can just docker run -it python:3-slim bash and then do whatever you want, no sudo required since you are root in the container (though you will need to get your code into the container). The dockerfile is just the way to layout your setup steps and be able build on diverse machines and to spin up multiple containers of your code.

@Kentoseth
Copy link
Author

Thank you.

I am closing this issue for now, so that I can tinker with Docker and the instructions you guys provided.

I will (try to) blog about using the slim version once I understand it myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants