How to Install Python from command line and Docker on Linux
Introduction We will see how we can install Python from command line using pyenv…
May 20, 2022
So you have a Django project, and want to run it using docker image. We will run it on Apache and Python 3.9.
Make sure, you have a running Django project, before proceeding.
First we will create a base image, where we will install following:
FROM centos:7
USER root
RUN yum makecache fast \
&& yum -y install epel-release \
&& yum -y update \
&& yum groupinstall "Development Tools" -y \
&& yum install openssl-devel libffi-devel bzip2-devel -y \
&& yum install httpd httpd-devel mod_ssl wget -y \
&& yum clean all \
&& rm -rf /var/cache/yum
RUN wget https://www.python.org/ftp/python/3.9.10/Python-3.9.10.tgz \
&& tar xvf Python-3.9.10.tgz \
&& cd Python-3.9.10/ \
&& ./configure --prefix=/usr/local --enable-optimizations --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib" \
&& make altinstall \
&& python3.9 --version \
&& python3.9 -m pip install --upgrade pip \
&& pip3.9 install virtualenv
Build this image,
docker build -t django_base .
# Using multi-stage builds to avoid showing secrets in docker history
FROM python38_test as intermediate
WORKDIR /var/www/html/
COPY . /var/www/html/
RUN virtualenv env --python python3.9 \
&& source /var/www/html/env/bin/activate \
&& python3.9 -m pip install -r /var/www/html/requirements.txt \
&& python3.9 -m pip install mod_wsgi \
&& virtualenv env --python python3.9 \
&& source /var/www/html/env/bin/activate \
&& mod_wsgi-express install-module
COPY ./docker/httpd.conf /etc/httpd/conf/httpd.conf
COPY ./docker/sites-enabled /etc/httpd/sites-enabled
ENV CONFIG "/var/www/html"
EXPOSE 8080
USER root
CMD ["/usr/sbin/httpd","-D","FOREGROUND"]
Build this image.
Note, if you are installing pip modules from a private artifactory, See other post on How to securely create docker image
Now, just pass your required environment variables to your app and run. It will run on port 8080. You can use this image either on Kubernetes or regular docker run environment.
Thanks for reading
Introduction We will see how we can install Python from command line using pyenv…
Introduction In this post, we will see Python 3.9.x patch for FIPS enabled…
Introduction In a normal email sending code from python, I’m getting following…
Lets implement a command shell by using a command dispatcher. The objective is…
Introduction We will see how we can install Python 3.7 on Windows without UI. i…
Introduction To give some context, I have two python files. (Both in same folder…
Introduction In this post we will see following: How to schedule a job on cron…
Introduction There are some cases, where I need another git repository while…
Introduction In this post, we will see how to fetch multiple credentials and…
Introduction I have an automation script, that I want to run on different…
Introduction I had to write a CICD system for one of our project. I had to…
Introduction Java log4j has many ways to initialize and append the desired…