Python or Py not found in docker image - python

Below is my docker file
FROM ubuntu:latest
RUN apt-get update -y
RUN apt-get update && apt-get install -y telnet && apt-get install -y ksh && apt-get install -y curl && apt-get install -y python2.7.x python-dev build-essential && apt-get -y clean && rm -rf /var/lib/apt/lists/*
RUN curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
RUN python get-pip.py
RUN pip install pymssql==2.1.3
ENTRYPOINT ['py']
I am getting the below error (py not found in docker image)
I tried replacing 'py' with 'python' and still it complains that 'python' not found in docker image

in the entrypoint command you must use double quote like this:
ENTRYPOINT ["py"]

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

How To Install latest python version in dockerfile that include jenkins/jnlp-slave:latest

I have issue with my dockerfile:
I tried to add latest python version (3.9 or 3.8) but when
My dockerfile:
FROM jenkins/jnlp-slave:latest
USER root
ENV AWS_ACCESS_KEY_ID ****************
ENV AWS_SECRET_ACCESS_KEY ***************
ENV AWS_DEFAULT_REGION ***********
ENV AWS_DEFAULT_OUTPUT ************
RUN apt-get update
RUN apt-get install vim nano expect sshpass curl apt-transport-https -y
**RUN apt install python3.9 -y**
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
RUN apt-get install -y libcurl4-gnutls-dev librtmp-dev
COPY pythonRequirements.txt pythonRequirements.txt
RUN mkdir ~/.aws/ && touch ~/.aws/config
RUN apt-get update
RUN apt-get install -y tcpdump
RUN apt-get install jq -y
RUN apt-get install -y pkg-config
RUN apt install libcairo2-dev -y
RUN pip3 install -r pythonRequirements.txt --no-cache-dir
RUN apt-get install -y libsm6 libxext6 libxrender-dev python3-tk
RUN curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
RUN echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | tee -a /etc/apt/sources.list.d/kubernetes.list
RUN apt-get update
RUN apt-get install -y kubectl
RUN mkdir ~/.kube
RUN apt-get install xvfb -y
RUN pip3 install psycopg2-binary
RUN aws s3 cp s3://*************************
RUN aws s3 cp s3://*************************
RUN aws s3 cp s3://*************************
RUN aws s3 cp s3://*************************
When I tried it and then I checked the python version I got python 3.5!!!
My docker file must include FROM jenkins/jnlp-slave:latest

cant open .env/activate in docker compose but work in docker build

Following is my docker file
FROM ubuntu:18.04
# Upgrade installed packages
RUN apt update
RUN apt upgrade -y
ENV TZ=Europe/London
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get install -y libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
WORKDIR /code
RUN apt-get -y install python3-pip
RUN apt-get -y install python3-venv
RUN apt -y install python3-setuptools libffi-dev python3-dev
RUN apt install -y curl
RUN apt install -y unzip
RUN apt-get install -y build-essential swig
WORKDIR /code
RUN python3 -m venv .env
RUN . .env/bin/activate && pip install --upgrade pip && curl https://raw.githubusercontent.com/automl/auto-sklearn/master/requirements.txt | LC_ALL=C.UTF-8 xargs -n 1 -L 1 pip install
COPY requirements.txt requirements.txt
RUN . .env/bin/activate && pip install pyenchant && pip install -r requirements.txt
RUN apt install -y libgl1-mesa-glx
RUN apt-get install -y libglib2.0-0
RUN apt-get install -y libenchant1c2a
RUN mkdir embeddings
COPY . .
RUN curl -L http://nlp.stanford.edu/data/glove.6B.zip --output glove.zip
RUN unzip -o glove.zip -d embeddings/
RUN . .env/bin/activate && python nltk_install.py
CMD . .env/bin/activate && python main.py
It works when built using docker build .
Docker-compose file
version: "3.9" # optional since v1.27.0
services:
pythonscripts:
build: .
volumes:
- "/mnt/d/code/data1/:/code/data/"
But when i try with docker-compose using docker-compose up. it gives following error:
Successfully built 06caf1786bfe
Successfully tagged openbotsdocumentsautomlpythonscripts_pythonscripts:latest
WARNING: Image for service pythonscripts was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating openbotsdocumentsautomlpythonscripts_pythonscripts_1 ... done
Attaching to openbotsdocumentsautomlpythonscripts_pythonscripts_1
pythonscripts_1 | /bin/sh: 1: .: Can't open .env/bin/activate
openbotsdocumentsautomlpythonscripts_pythonscripts_1 exited with code 2

where can i get older version of this package as new version is failing my Docker build?

My docker build is failing after there is an update to this package (https://packages.microsoft.com/debian/9/prod/dists/stretch/main/binary-amd64/Packages.bz2) I want a version of this package before the update happened (24-Jun-2020 15:09 ).
after adding the URL to source.list, apt-get update -y is failing.
Docker File :
FROM python:3.6.8
WORKDIR /app
ADD . /app
RUN apt-get update -y
RUN apt-get install python-pip -y
RUN apt-get -y update && apt-get install -y --no-install-recommends apt-utils apt-transport-https
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update -y
RUN ACCEPT_EULA=Y apt-get -y install msodbcsql17
RUN ACCEPT_EULA=Y apt-get -y install mssql-tools
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
RUN echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
RUN /bin/bash -c "source ~/.bashrc"
RUN apt-get install unixodbc-dev
RUN pip install -r requirements.txt
EXPOSE 4040
CMD ["newrelic-admin","run-program","gunicorn", "-c", "gunicorn_config.py", "main:app"]
That error usually indicates a problem with the package repository on the server side (you can test from other client machines/networks to be sure). If you can report it to someone at Microsoft, it usually gets fixed pretty quickly and you can try again after that.

Couldn't find any package by regex in python:3.8.3 docker image

I'm new to docker and I created a docker image and this is how my docker file looks like.
FROM python:3.8.3
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
postgresql-client \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get install -y gcc libtool-ltdl-devel xmlsec1-1.2.20 xmlsec1-devel-1.2.20 xmlsec1 openssl-
1.2.20 xmlsec1-openssl-devel-1.2.20 \
&& apt-get -y install curl gnupg \
&& curl -sL https://deb.nodesource.com/setup_14.x | bash - \
&& apt-get -y install nodejs
WORKDIR /app/
COPY . /app
RUN pip install -r production_requirements.txt \
&& front_end/noa-frontend/npm install
This image is used in docker-compose.yml's app service. So when I run the docker-compose build, I'm getting the below error saying it couldn't find the package. Those are few dependencies which I want to install in order to install a python package.
In the beginning, I've run the apt-get update to update the package lists.
Can anyone please help me with this issue.
Updated Dockerfile
FROM python:3.8.3
RUN apt-get update
RUN apt-get install -y postgresql-client\
&& apt-get install -y gcc libtool-ltdl-devel xmlsec1-1.2.20 xmlsec1-
devel-1.2.20 xmlsec1 openssl-1.2.20 xmlsec1-openssl-devel-1.2.20 \
&& apt-get -y install curl gnupg \
&& curl -sL https://deb.nodesource.com/setup_14.x | bash - \
&& apt-get -y install nodejs
WORKDIR /app/
COPY . /app
RUN pip install -r production_requirements.txt \
&& front_end/noa-frontend/npm install
You are trying to use apt-get install after doing rm -rf /var/lib/apt/lists/*. That is guaranteed not to end well. Try removing the rm command initially to see if that helps. If you really need to keep the size of the image down then put the rm command as the very last command in the run statement.
If you really want to reduce your image size then try switching to using python:3.8-slim or python:3.8-alpine. Alpine is a different OS to the default of Ubuntu, but its package manager can be told not to cache files locally. eg.
FROM python:3.8-alpine
RUN apk add --no-cache postgresql-client
RUN apk add --no-cache gcc libtool-ltdl-devel xmlsec1-1.2.20 xmlsec1-devel-1.2.20 xmlsec1 \
openssl-1.2.20 xmlsec1-openssl-devel-1.2.20
RUN apk add --no-cache curl gnupg
RUN apk add --no-cache nodejs
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
WORKDIR /app/
COPY . /app
RUN pip install -r production_requirements.txt \
&& front_end/noa-frontend/npm install
Certain bits of software might be available under different package names, so you'll have to check that out.
The instruction rm -rf /var/lib/apt/lists/* is more or less negating apt-get update. APT is no longer able to access the list of available packages after that. Move the rm to the end (and perhaps consider using the safer apt-get clean all).

Categories