-
-
Save thinkingerrol/ba1c1e16c8fd487508ca2b9d0297a224 to your computer and use it in GitHub Desktop.
# inspired by: | |
# https://gist.github.com/BrutalSimplicity/882af1d343b7530fc7e005284523d38d | |
# and minimized thanks to: | |
# https://stackoverflow.com/questions/72102435/how-to-install-python3-6-on-ubuntu-22-04 | |
FROM ubuntu:22.04 | |
# ensure we use bash for all RUN commands | |
# use -l to use interactive login shell | |
# and ensure modifications to bashrc are properly sourced | |
SHELL ["/bin/bash", "-lc"] | |
# Install basic dev packages | |
RUN apt-get clean && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ | |
make build-essential libssl-dev zlib1g-dev \ | |
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \ | |
libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev \ | |
libgdbm-dev libnss3-dev libedit-dev libc6-dev \ | |
git \ | |
&& rm -rf /var/lib/apt/lists/* | |
RUN apt-get clean && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ | |
ca-certificates \ | |
&& rm -rf /var/lib/apt/lists/* | |
# installing openssl because saw this in /tmp/python-build*.log: | |
# warning: openssl 0x00000000 is too old for _hashlib | |
RUN apt-get clean && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ | |
openssl \ | |
&& rm -rf /var/lib/apt/lists/* | |
RUN git config --global advice.detachedHead false | |
RUN git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.11.3 | |
# prepending asdf because bash knows we are not interactive and returns early from .bashrc | |
RUN sed -i '1s;^;source $HOME/.asdf/asdf.sh\nsource $HOME/.asdf/completions/asdf.bash\n;' ~/.bashrc | |
RUN asdf plugin add python | |
# prefixing "asdf install" due to https://stackoverflow.com/questions/70064631/python3-5-m-ensurepip-segmentation-fault | |
# CC=clang would be the other solution, but "apt install clang" says "557 MB of additional disk space will be used" | |
RUN PYTHON_CFLAGS='-O2' asdf install python 3.6.9 | |
RUN echo XXXXX | |
RUN cat /tmp/python-build*.log | |
RUN echo YYYYY | |
RUN asdf global python 3.6.9 | |
RUN pip install --upgrade pip | |
# RUN pip install pipenv | |
RUN python3 --version | |
RUN pip3 --version | |
RUN \ | |
pip3 install --no-cache-dir -i https://artifactory.funkwerk-itk.com/api/pypi/pypi-virtual/simple --upgrade \ | |
setuptools==59.6.0 gcovr pep8==1.7.1 pylint==2.10.2 autopep8==1.3.5 pydocstyle==2.1.1 pycodestyle==2.3.1 \ | |
flake8==3.5.0 flake8-blind-except==0.1.1 flake8-docstrings==1.3.0 autoflake==1.1 \ | |
flake8_quotes==0.13.0 flake8-isort==3.0.1 mccabe==0.6.1 pyflakes==1.6.0 \ | |
autobahn selenium==3.13.0 behave==1.2.6 aiohttp==3.6.2 pymongo polib==1.1.0 \ | |
psycopg2-binary \ | |
docker==3.2.1 dockerpty==0.4.1 ipywidgets pyaml | |
# make pylint and whatnot available by reshimming | |
RUN asdf update && asdf reshim python 3.6.9 | |
# Set the working directory | |
WORKDIR /app | |
# Copy your application files to the container (if needed) | |
COPY . /app | |
# Specify the default command to run when the container starts | |
CMD ["python", "your_script.py"] | |
# set all the things to be sure bash is always used as the default shell | |
RUN cd /bin && ln -sf bash sh && chsh -s /bin/bash | |
ENV SHELL=bash | |
ENV PATH=$PATH:/root/.bin | |
ENTRYPOINT [ "/bin/bash", "-lc" ] |
dive shows the largest layer is 797MB, of which:
102MB occupied by /usr/lib/gcc,
101MB by /usr/bin
390MB by /usr/lib/x86_64-linux-gnu
114MB by /usr/share
should look into https://www.augmentedmind.de/2022/02/06/optimize-docker-image-size/
unfortunately I do need python 3.6.9 and trying to install it I get a segmentation fault, similar to
https://stackoverflow.com/questions/72102435/how-to-install-python3-6-on-ubuntu-22-04
even after adding all packages mentioned in the SO answer:
libncurses5-dev \
libgdbm-dev \
libnss3-dev \
libedit-dev \
libc6-dev \
I get
Downloading python-build...
Cloning into '/root/.asdf/plugins/python/pyenv'...
python-build 3.6.9 /root/.asdf/installs/python/3.6.9
Downloading Python-3.6.9.tar.xz...
-> https://www.python.org/ftp/python/3.6.9/Python-3.6.9.tar.xz
Installing Python-3.6.9...
BUILD FAILED (Ubuntu 22.04 using python-build 2.3.20-3-g38ac7472)
Inspect or clean up the working tree at /tmp/python-build.20230615163935.85
Results logged to /tmp/python-build.20230615163935.85.log
Last 10 log lines:
if test "xupgrade" != "xno" ; then \
case upgrade in \
upgrade) ensurepip="--upgrade" ;; \
install|*) ensurepip="" ;; \
esac; \
LD_LIBRARY_PATH=/tmp/python-build.20230615163935.85/Python-3.6.9 ./python -E -m ensurepip \
$ensurepip --root=/ ; \
fi
Segmentation fault (core dumped)
make: *** [Makefile:1102: install] Error 139
The command '/bin/bash -lc asdf install python 3.6.9' returned a non-zero code: 1
I'm not the only one experiencing similar issue with asdf in ubuntu 22.04: even with newer python 3.7.3
asdf-community/asdf-python#151
https://stackoverflow.com/questions/70064631/python3-5-m-ensurepip-segmentation-fault
... fix installation via pyenv, asdf and probably others:
export PYTHON_CFLAGS='-O2'
others got around it (?) by CC=clang
or building python 3.7.12
could not pin pylint==2.10.2 (installs fine but then bash: pylint: command not found
), without pinning getting 2.13.9 just fine
nah, same, until I do RUN asdf update && asdf reshim python 3.6.9
got as far as being able to run our 3.6.9 based python code successfully under ubuntu 22.04 where normal python is 3.10.
however, only as root: we have an elaborate dev container spawner script that calls "useradd" and mimicks the host $USER inside the fresh container, and I haven't been able to make it transparently "source" the asdf initialization scripts or do the re-shimming, even after installing asdf under /opt instead of /root and following asdf-vm/asdf#577
so for now I'm giving up on 3.6.9 under ubuntu 22.04 and will try to instead upgrade our python code.
focusing on python; if we install aptitude we see that python3.10 is brought by lsb-release:
aptitude why python3.10