Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

install python3 and python pip in docker

Create Dockerfile : 

FROM python:3-alpine

RUN python -m pip install --upgrade pip

RUN pip3 install requests paho-mqtt

COPY NumSide.py /home/mehdi/Download/NumSide.py

CMD ["python","/home/mehdi/Download/NumSide.py"]
Comment

docker install python

# Python
FROM ubuntu:18.04

ARG PYTHON_VERSION=3.9.1
ENV DEBIAN_FRONTEND=noninteractive
ENV PATH $PATH:/usr/local/bin

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=aptcache1804 --mount=type=cache,target=/var/lib/apt,sharing=locked,id=aptcache1804 
    export DEBIAN_FRONTEND=noninteractive 
    && apt-get update -y 
    && apt-get install -y apt-utils sudo wget tar 

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=aptcache1804 --mount=type=cache,target=/var/lib/apt,sharing=locked,id=aptcache1804 
    export DEBIAN_FRONTEND=noninteractive 
    && apt-get update -y 
    && apt-get install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev

RUN wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz 
    && tar -xf Python-${PYTHON_VERSION}.tgz
  
RUN cd Python-${PYTHON_VERSION} 
    && ls -la 
    && ./configure --enable-optimizations 
    && make -j 4 
    && make altinstall
    
RUN pip3 install requests asyncio

COPY ./entrypoint.py ./entrypoint.py

ENTRYPOINT python ./entrypoint.py
Comment

install python docker

# install python
docker pull python

# run python in interactive mode with no persistent storage
docker run -it python

# run python in interactive mode and mount an absolute path
# to a folder named shared in the python container for persistent storage
docker run -it -v /Users/codecaine/Desktop:/shared  python  

# run python in interactive mode and mount the terminal current working directory
# to a folder named shared in the python container for persistent storage
docker run -it -v ${PWD}:/shared python
# create a volume named shared
volume to create my_volume

# get a list of volumes on system
docker volume ls

# to attach a volume for persistent storage in python
docker run -it -v my_volume:/shared  python

# in python check the folder
import os

# change system directory to shared folder
os.chdir("shared")

# list files in the current directory
os.listdir(".")

# stop all active services - containers and mounted volumes
docker system prune

# remove a volume is storage is not needed anymore
docker volume rm my_volume

Comment

install python3 in dockerfile

RUN apk upgrade --update && apk add --no-cache python3 python3-dev
Comment

PREVIOUS NEXT
Code Example
Shell :: drop cache ubuntu 
Shell :: terminal delete directory not empty 
Shell :: win32gui python 
Shell :: view git settings 
Shell :: powershell create symlink 
Shell :: connect to wifi linux 
Shell :: ubuntu open file from terminal 
Shell :: pm2 typescript 
Shell :: install aws cli 
Shell :: linux refresh .bashrc 
Shell :: monitor mode wifi kali 
Shell :: git diff only file names 
Shell :: progress bar file.tar.xz extract 
Shell :: conda install flask-cors 
Shell :: bash how to pass shell variables to awk 
Shell :: bash count duplicate lines in a file 
Shell :: ffmpeg mkv to mp4 
Shell :: start docker in fedora 
Shell :: bash script: replace . with : 
Shell :: ls all subdirectories 
Shell :: install cv2 
Shell :: how to get list of users in ubuntu 
Shell :: git how to archive a branch 
Shell :: restart computer command linux 
Shell :: awk sum column 
Shell :: venv deactivate 
Shell :: npm bootstrap 
Shell :: renaming a docker container 
Shell :: ubuntu icons missing on taskbar 
Shell :: setting sublimeREPL in linux 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =