Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker image with python & alpine failure due missing compiler error

I'm looking for a docker image with both python3 and a crontab. When I use python:latest as a base, I have no cron, but all required python packages install without problem.

When I use alpine as a base I have the (busybox) cron working, but are unable to install specific python package due to compiler error.

The same applies when I use python:alpine.

Collecting pynacl>=1.0.1 (from paramiko->-r required_python_packages.txt (line 6))
  Downloading PyNaCl-1.1.2.tar.gz (3.1MB)
    Complete output from command python setup.py egg_info:

        No working compiler found, or bogus compiler options
        passed to the compiler from Python's distutils module.
        See the error messages above.

Any advise?

like image 506
Bigfoot Avatar asked Jul 11 '17 07:07

Bigfoot


People also ask

Which Docker image is best for Python?

If you want the absolute latest bugfix version of Python, or a wide variety of versions, the official Docker Python image is your best bet. If you want the absolute latest system packages, you'll want Ubuntu 22.04; RedHat 9 is somewhat more conservative, for example including Python 3.9 rather than 3.10.

Can you Dockerize Python?

Docker supports Python containers that use the import requests command. There are also multiple images on Docker Hub that can accommodate such use cases.

What is Python slim Docker image?

The slim image is a paired down version of the full image. This image generally only installs the minimal packages needed to run your particular tool. In the case of python, that's the minimum packages to run python and the same for node.


1 Answers

You need a working compiler, the easiest way around this is to install the build-base package like so:

apk add --no-cache --virtual .pynacl_deps build-base python3-dev libffi-dev

This will install various tools that are required to compile pynacl and pip install pynacl will now succeed.

Note it is optional to use the --virtual flag but it makes it easy to trim the image because you can run apk del .pynacl_deps later in your Dockerfile as they are not needed any more and would reduce the overall size of the image.

like image 51
Clive Makamara Avatar answered Sep 30 '22 07:09

Clive Makamara