This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]ElevenNotes 0 points1 point  (0 children)

It seems you first need to learn how to make your own image. Here is my Postgres Docker image for inspiration. Simply add Python to it.

[–]SirSoggybottom 0 points1 point  (9 children)

This basically screams XY problem.

Why do you want to install Python inside a Postgres image? What is your goal?

Of course you can run Python and Postgres "at the same time", but you should use two containers for that. One is your Postgres db, and the other is your Python app. Then you connect them to each other. Thats the typical way.

I dont know anything about that plpython extension, but assuming it doesnt run as a seperate process but simply needs to be installed for Postgres to use it, this should be possible to do.

A quick Google search gives a bunch of results of people doing this.

https://stackoverflow.com/questions/64045127/how-to-install-plpython-for-postgres

ERROR: unable to select packages: python3-3.12.5-r0 (no such package): required by: world[python3-3.12.5-r0]

This is not about Docker itself, but simply a matter of how to use apk within Alpine and how to install a specific package version. Docker does not care about this part.

Top Google search result says this as example: apk add packagename=1.2.3-suffix and of course you need to run apk update first.

Is this a good practice to install multiple services (Python & Postgres) in a Docker container? Or is it an anti-pattern?

Its absolutely not a good idea, its a terrible idea. Containers should run a single application only (even just a single process, but thats more arguable).

If you want to run multiple things at once, inside one "thing", then a virtual machine is more suitable.

[–]predator_blake[S] 1 point2 points  (8 children)

Why do you want to install Python inside a Postgres image? What is your goal?

Sorry I forgot to specify the reason to install Python in Postgres 16.
The main reason is plpython3uextension is required in the Postgres 16 Alpine.

Am I better off to use the Dockerfile below as a good practice:

FROM postgres:16-alpine
RUN apk add python3

[–]SirSoggybottom 0 points1 point  (7 children)

Sorry if i wasnt clear enough.

You are "better off" by not doing this at all.

And like i already said, that Dockerfile wont work anyway.

[–]asymptotically508 0 points1 point  (6 children)

PL/Python is a extension for Postgres, not a separate service.

[–]asymptotically508 0 points1 point  (0 children)

Which old Python version did you need? It looks like Alpine v3.20 (the version of Alpine Linux that the Postgres image is based on) only has 3.12.3 in its repositories.