问题
I am trying to build a minimal docker image, capable of nothing more but running the Python interpreter. During development I start from alpine, the final image will be build FROM scratch
. I am working on a Linux Mint machine.
I am able to compile the Python compiler and install it into my current working directory like this:
cd Python-3.8.7
./configure --prefix=$PWD/../python
make install
However, I did not find out how to tweak the --prefix
settings correctly so that the created shebangs will later work in the docker container.
First line of ./python/pip3
contains the absolute path of my host and reads
#!/home/orion/minimal_py_image/Python-3.8.7/../python/bin/python3.8
But it should read
#!/python/bin/python3.8
because /python
is the location under which the Python interpreter will be found in the docker image.
How can I trick the make install
script so that the final destination will be /python/bin
?
I would like to keep the build contained in the current directory i.e. not using the folder /python
on the host where I do the compilation.
Additional Information
Probably not directly relevant for this question but as reference: Here is the Dockerfile I am trying to get working:
FROM alpine
COPY python /python
COPY lib64/* /lib64/
ENV LD_LIBRARY_PATH=/usr/lib64/:/lib64/:/python/lib
ENV PATH="${PATH}:/python/bin"
I am capable of running Python already with docker run -it mini python3 -c "print('hello from python')"
but pip is not working yet due-to the wrong shebang.
回答1:
A common convention in Autoconf-based build systems is to support a Make variable DESTDIR
. When you run make install
, if DESTDIR
is set, it actually installs into the configured directory under DESTDIR
, but still built with the original path. You can then create an archive of the target directory, or in a Docker context, use that directory as the build context.
cd Python-3.8.7
# Use the final install target as the --prefix
./configure --prefix=/python
# Installs into e.g. ../python/python/bin/python3.8
make install DESTDIR=../python
cd ../python
tar cvzf ../python.tar.gz .
You can see this variable referenced in the Python Makefile in many places.
来源:https://stackoverflow.com/questions/65869903/how-to-configure-shebang-line-of-internal-python-tools