lazyycoder
Published in

lazyycoder

Installing python 3, pip and boto3 on centos docker

Here are the steps to install python 3 on docker.

  1. First download the appropriate docker image:
docker pull centos

2. Start the docker container:

docker run -it -name boto3-centos centos

The -name parameter ensures that the container has the name boto3-centos . You could name it whatever you find reasonable

Install GCC compiler and other dependencies for python:

yum install gcc openssl-devel bzip2-devel libffi-devel zlib-devel -y

4. Download python 3.7.x:

curl https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz --output Python-3.7.9.tgz

5. Extract the tgz file

tar xzf Python-3.7.9.tgz

6. Install Python

cd Python-3.7.9
./configure --enable-optimizations
yum install make -y
make altinstall

7. Verify the version of python

python3.7 -V>> Python 3.7.9
rm /usr/src/Python-3.7.9.tgz

Install pip:

yum -y install epel-release
curl https://bootstrap.pypa.io/get-pip.py --output get-pip.py
python3.7 get-pip.py
pip -V

Create a virtualenv

python3.7 -m venv my-venv

Activate the virtualenv

source my-venv/bin/activate

You are in your own virtual env and doing a pip freeze should give you an empty list

If your project has a set of python libs it needs, then add it to a requirements.txt file. Below is an example of the contents of requirements.txt with only boto3 as a necessary package

boto3==1.15.11

Install your packages in the virtual env

pip install -r requirements.txt

Now when you do pip freeze you will see boto3 and all its dependencies installed

Alternate versionyum update -y[root@a32ad429b1bb Python-3.7.9]# yum install python3Failed to set locale, defaulting to C.UTF-8Last metadata expiration check: 0:51:13 ago on Sat Oct  3 05:24:50 2020.Dependencies resolved.================================================================================Package             Arch   Version                             Repo       Size================================================================================Installing:python36            x86_64 3.6.8-2.module_el8.1.0+245+c39af44f AppStream  19 kInstalling dependencies:platform-python-pip noarch 9.0.3-16.el8                        BaseOS    1.8 Mpython3-pip         noarch 9.0.3-16.el8                        AppStream  19 kpython3-setuptools  noarch 39.2.0-5.el8                        BaseOS    162 kEnabling module streams:python36                   3.6Transaction Summary================================================================================Install  4 PackagesTotal download size: 2.0 MInstalled size: 7.8 M

If you wanted to do this in a repeatable way, use the following Dockerfile:

Dockerfile for building image with python, pip and boto3

Copy the contents of the above and save it as Dockerfile . Then,

docker build . -t python-pip-boto3:0.1.1
docker run -it python-pip-boto3:0.1.1

You will now be inside a terminal running the in the container. Since the above dockerfile installs boto3 facilities for you, you can now use it in the python shell in the docker container:

[root@f81c0a1e50c3 tmp]# pip freeze
boto3==1.15.11
botocore==1.18.18
jmespath==0.10.0
python-dateutil==2.8.1
s3transfer==0.3.4
six==1.15.0
urllib3==1.25.11

References:

--

--

--

A lazy coder works hard to write the most succint code

Recommended from Medium

Phase 1: Ammo Count

Higher Order Function and its uses in Swift 4

Zoom Robot Framework Mob Testing — Tentamen Software Testing Blog

Stay in Destiny World: GIVEAWAY for Most Active Member

How To Avoid Project Overconstrain

Top Tools That Useful for Web developers

Bring your game to AAA status through Post Processing

Intermediate Google Tag Manager ‘Review’

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
lazy coder

lazy coder

A lazy coder who works hard to build good software that does not page you in the middle of the night!

More from Medium

Creating my first Lambda Function with Python in AWS

Mock AWS DynamoDB service for unit testing in Python

Create a Linux Machine and Connect via Hadoop to Pyspark for Data Extraction: Part 2

How to connect AWS Redshift Database using Python