Building docker image with Django 2.0 fails - python

I am currently building a docker image with the latest version of Django but during the build I get this:
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-9LueOB/Django/
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
The command '/bin/sh -c INSTALL_PKGS="python-pip oracle-instantclient-tnsnames.ora afs_tools_standalone nss_wrapper openssh-clients cx_Oracle libmemcached-devel python-ldap mod_wsgi httpd MySQL-python wassh-ssm-cern wassh" && INSTALL_PKGS_BUILD="gcc python-devel zlib-devel" && yum install -y centos-release-scl && yum update -y && yum install -y --setopt=tsflags=nodocs --enablerepo=centosplus $INSTALL_PKGS && yum install -y $INSTALL_PKGS_BUILD && rpm -e --nodeps centos-logos && pip install --upgrade && pip install -r requirements.txt && rm requirements.txt && yum remove -y $INSTALL_PKGS_BUILD && yum clean all -y && rm -rf /var/cache/yum && mkdir /var/django/ && mkdir -p /var/django/home/ && mkdir -p /usr/local/bin/ && mkdir -p /run/httpd/ && chown -R root:root /run/httpd && chmod a+rw /run/httpd' returned a non-zero code: 1
On my requirements.txt I am using this:
Django==2.0
djangorestframework==3.2.1
pyapi-gitlab==7.8.4
pylibmc==1.5.0
django-logtail
python-gitlab
Any idea of why this is happening?

I believe it's because Django 2.0 doesn't support Python 2.x anymore, try to replace "python" by "python3" in your command.
EDIT: or run "pip3" instead of "pip" when you install Django>=2.0
as mentioned by Piinthesky here you'll find the relevant Django documentation

Related

How do i update pyjwt from 2.3.0 to 2.4.0 in Dockerfile ubuntu 22.04?

We found 1 vulnerability in base docker image "pyjwt version 2.3.0 has 1 vulnerability" Fixed in version pyjwt 2.4.0
Below is the Dockerfile
FROM ubuntu:22.04
# hadolint ignore=DL3015
# hadolint ignore=DL3008
RUN apt-get clean
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get -y update
RUN apt-get -y upgrade apt \
&& apt-get install -y unoconv ghostscript software-properties-common \
&& add-apt-repository ppa:ondrej/php -y \
&& apt -y install php7.4 \
&& apt-get install -y curl jq php7.4-bcmath php7.4-xml zip unzip php7.4-zip \
&& apt-get install -y php7.4-fpm php7.4-amqp composer nginx openssl php7.4-curl ca-certificates \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" \
&& unzip awscliv2.zip \
&& ./aws/install \
&& rm awscliv2.zip
# Setup services
COPY ./src/scripts/nginx.conf /etc/nginx/nginx.conf
COPY ./src/scripts/run.sh /opt/run.sh
RUN chmod -R a+rw /etc/nginx
RUN chmod -R a+rw /etc/php/7.4/fpm
RUN chmod +x /opt/run.sh
EXPOSE 8080 8443
CMD [ "/opt/run.sh" ]
I have tried many things like update installing python3 and updating pyjwt package with pip install pyjwt==2.4.0. But it didn't work. It seems like one of the above package from Dockerfile is using pyjwt(2.3.0) and I don't know how do i update it.
You can try uninstall python3-jwt package with apt and install new version with pip
RUN apt purge --autoremove python3-jwt -y
RUN pip3 install PyJWT==2.4.0

Why is pdftocairo not getting installed when installing poppler?

I am using the following command in the dockerfile to install poppler
RUN wget --directory-prefix=~ poppler.freedesktop.org/poppler-22.04.0.tar.xz -O /tmp/poppler-22.04.0.tar.xz && apt-get install xz-utils && tar xf /tmp/poppler-22.04.0.tar.xz -C /tmp && cd /tmp/poppler-22.04.0 && ls && mkdir build && cd build && apt-get -y install libfreetype6-dev && apt-get -y install pkg-config && apt-get -y install libfontconfig1-dev && apt-get -y install libjpeg-dev && apt-get -y install libopenjp2-7-dev && apt-get -y install build-essential cmake && cmake -DENABLE_BOOST=OFF .. && make && make install
When I exec inside the container and do
pdftocairo -v
it says command not found. However when I do
pdftotext -v
I get the following output
pdftotext version 22.04.0
Copyright 2005-2022 The Poppler Developers - http://poppler.freedesktop.org
Copyright 1996-2011, 2022 Glyph & Cog, LLC
Was expecting something similar for pdftocairo also as I need the library to convert pdf files to jpeg images. Can someone explain why this is happening ?

Can't install pip and python & ansible using Dockerfile in CentOS

I am trying to install python and pip & Ansible using Dockerfile but I get this error
/bin/sh: 1: python: not found
The command '/bin/sh -c curl -O https://bootstrap.pypa.io/pip/2.7/get-pip.py && python get-pip.py && python -m pip install --upgrade "pip < 21.0" && pip install ansible --upgrade' returned a non-zero code: 127
ERROR: Service 'jenkins' failed to build : Build failed
Here is my Dockerfile:
FROM jenkins/jenkins
USER root
RUN curl -O https://bootstrap.pypa.io/pip/2.7/get-pip.py && \
python get-pip.py && \
python -m pip install --upgrade "pip < 21.0" && \
pip install ansible --upgrade
USER jenkins
Note: I used the same instructions on another Dockerfile and it went without errors. Here is the Dockerfile from CentOS image:
FROM centos:7
RUN yum update -y && \
yum -y install openssh-server && \
yum install -y passwd
RUN useradd remote_user && \
echo "password" | passwd remote_user --stdin && \
mkdir /home/remote_user/.ssh && \
chmod 700 /home/remote_user/.ssh
COPY remote-key.pub /home/remote_user/.ssh/authorized_keys
RUN chown remote_user:remote_user -R /home/remote_user && \
chmod 600 /home/remote_user/.ssh/authorized_keys
RUN /usr/sbin/sshd-keygen
RUN yum -y install mysql
RUN curl -O https://bootstrap.pypa.io/pip/2.7/get-pip.py && \
python get-pip.py && \
python -m pip install --upgrade "pip < 21.0" && \
pip install awscli --upgrade
CMD /usr/sbin/sshd -D
Since I'm not entirely sure my comments were fully understandable, here is how I would install ansible in your current base image jenkins/jenkins.
Notes:
I fixed the tag to lts since building from latest is a bit on the edge. You can change that to whatever tag suits your needs.
That base image is itself based on Ubuntu and not CentOS as reported in your title (hence using apt and not yum/dnf)
I used two RUN directives (one for installing python, the other for ansible) but you can merge them in a single instruction if you want to further limit the number of layers.
FROM jenkins/jenkins:lts
USER root
RUN apt-get update && \
apt-get install -y python3-pip && \
rm -rf /var/lib/apt/lists/*
RUN pip install --upgrade pip && \
pip install ansible && \
pip cache purge
USER jenkins
I deleted RUN instructions and replaced it with :
RUN apt-get update
RUN apt-get install -y ansible
Worked like a charm.

Minimize docker image with python and R

I have the following Dockerfile:
FROM ubuntu:latest
RUN apt-get update \
&& apt-get install -y python3-pip python3-dev \
&& cd /usr/local/bin \
&& ln -s /usr/bin/python3 python \
&& pip3 install --upgrade pip
# Setup the Python's configs
RUN pip install --upgrade pip && \
pip install --no-cache-dir matplotlib==3.0.2 pandas==0.23.4 numpy==1.16.3 && \
pip install --no-cache-dir pybase64 && \
pip install --no-cache-dir scipy && \
pip install --no-cache-dir dask[complete] && \
pip install --no-cache-dir dash==1.6.1 dash-core-components==1.5.1 dash-bootstrap-components==0.7.1 dash-html-components==1.0.2 dash-table==4.5.1 dash-daq==0.2.2 && \
pip install --no-cache-dir plotly && \
pip install --no-cache-dir adjustText && \
pip install --no-cache-dir networkx && \
pip install --no-cache-dir scikit-learn && \
pip install --no-cache-dir tzlocal
# Setup the R configs
RUN apt-get update
RUN apt-get install -y software-properties-common
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
RUN add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/'
RUN apt update
ENV DEBIAN_FRONTEND=noninteractive
RUN apt install -y r-base
RUN pip install rpy2==2.9.4
RUN apt-get -y install libxml2 libxml2-dev libcurl4-gnutls-dev libssl-dev
RUN echo "r <- getOption('repos'); r['CRAN'] <- 'https://cran.r-project.org'; options(repos = r);" > ~/.Rprofile
RUN Rscript -e "install.packages('BiocManager')"
RUN Rscript -e "BiocManager::install('ggplot2')"
RUN Rscript -e "BiocManager::install('DESeq2')"
RUN Rscript -e "BiocManager::install('RColorBrewer')"
RUN Rscript -e "BiocManager::install('ggrepel')"
RUN Rscript -e "BiocManager::install('factoextra')"
RUN Rscript -e "BiocManager::install('FactoMineR')"
RUN Rscript -e "BiocManager::install('apeglm')"
WORKDIR /
# Copy all the necessary files of the app to the container
COPY ./ ./
# Install the slider-input component
WORKDIR /slider_input
RUN pip install --no-cache-dir slider_input-0.0.1.tar.gz
WORKDIR /
EXPOSE 8050
# Launch the app
CMD ["python", "./app.py"]
It's used for running dash app that using R commands, and it works fine.
The problem is the size of the image.
I want to minimize the size of the image as minimal as possible, but everything I tried was unsuccessful because of the combination of python and R.
Do you have any idea how can I minimize this image, and provide the same functionality?
Use docker-slim to minimize and secure your docker images. docker-slim will profile your docker image and throw away what you don't need.
It has been used with Node.js, Python, Ruby, Java, Golang, Rust, Elixir and PHP (some app types) running on Ubuntu, Debian, CentOS, Alpine and even Distroless.
docker-slim is production ready, but consider testing your container before deploying it to production. Minify docker images by up to 30x while making it secure too!
A multi-stage build will allow you to omit the compiler toolchain, headers, etc.. from the final image, only including the resulting code.
A three-part tutorial for Python specifically starts here: https://pythonspeed.com/articles/smaller-python-docker-images/
And the generic Docker docs: https://docs.docker.com/develop/develop-images/multistage-build/

How to install xapian with Python 3.6 on Ubuntu 16.04?

I installed Python 3.6 on Ubuntu 16.04 on Docker using the ppa:jonathonf/python-3.6 repository. Now I'd like to install xapian so I can use it with Python. I have not found any ready-made packages, so I am trying to build it from sources. I set PYTHON3 and PYTHON3_LIB parameters to point to Python 3.6. During the build process I get the following error:
ImportError: libxapian.so.30: cannot open shared object file: No such file or directory
I tried xapian versions 1.3.7 and 1.4.5 without luck.
How can I install xapian?
Here's a Dockerfile to reproduce my error:
FROM ubuntu:16.04
RUN apt-get update \
&& apt-get install -y software-properties-common python-software-properties
RUN add-apt-repository ppa:jonathonf/python-3.6
RUN apt-get update \
&& apt-get install -y python3-pip docker.io python3.6 python3.6-dev software-properties-common \
python-software-properties build-essential wget unzip cmake python3-sphinx \
&& cd /usr/local/bin \
&& ln -s /usr/bin/python3.6 python
RUN python -m pip install --upgrade pip
# install xapian 1.4.5
RUN apt-get update && apt-get install -y curl uuid-dev zlib1g-dev
WORKDIR /root
RUN curl --silent --show-error --fail --next -O https://oligarchy.co.uk/xapian/1.4.5/xapian-core-1.4.5.tar.xz
RUN curl --silent --show-error --fail --next -O https://oligarchy.co.uk/xapian/1.4.5/xapian-bindings-1.4.5.tar.xz
RUN tar xvf xapian-core-1.4.5.tar.xz
RUN tar xvf xapian-bindings-1.4.5.tar.xz
WORKDIR /root/xapian-core-1.4.5
RUN ./configure && make && make install
WORKDIR /root/xapian-bindings-1.4.5
RUN ./configure PYTHON3=/usr/bin/python3.6 PYTHON3_LIB=/usr/lib/python3.6 --with-python3 && make && make install
RUN python -c "import xapian"
The problem is that the Xapian library (libxapian.so.30) is being installed into /usr/local/lib by default, but Ubuntu doesn't know that it's been put there yet. You can tell it by adding:
RUN ldconfig
after installing the core (so before you change WORKDIR to build the bindings).
There's some helpful information about ldconfig and library search paths on Ubuntu in the answers to this Unix Stackexchange question.

Categories