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

python docker

# syntax=docker/dockerfile:1
FROM python:3
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
Comment

install python in docker file

Generic Dockerfile template
Finally to give a comprehensive answer, note that a good practice regarding Python dependencies consists in specifying them in a declarative way in a dedicated text file (in alphabetical order, to ease review and update) so that for your example, you may want to write the following file:

requirements.txt

matplotlib
med2image
nibabel
pillow
pydicom
and use the following generic Dockerfile

FROM python:3

WORKDIR /usr/src/app

COPY requirements.txt ./

RUN pip install --no-cache-dir --upgrade pip 
  && pip install --no-cache-dir -r requirements.txt

COPY . .

CMD ["python", "./your-daemon-or-script.py"]
Comment

install python in docker file

FROM ubuntu:16.04

RUN apt-get update && apt-get install -y --no-install-recommends 
    python3.5 
    python3-pip 
    && 
    apt-get clean && 
    rm -rf /var/lib/apt/lists/*

RUN pip3 install nibabel pydicom matplotlib pillow
RUN pip3 install med2image
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 python in dockerfile

RUN apt-get update
RUN apt-get install python
Comment

install python3 in dockerfile

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

docker python

# getting a copy of ubuntu for docker
pull ubuntu

# run ubuntu image in interactive mode 
docker run -it ubuntu  

# run ubuntu image in interactive mode while mounting the terminal
# current working directory to ubuntu home folder
docker run -v ${PWD}:/home -it ubuntu

# run ubuntu image in interactive mode while mounting the terminal
# mounting an absolute path on my computer directory to ubuntu home folder
docker run -v /Users/codecaine/Desktop:/home -it ubuntu

# run ubuntu image in interactive mode while mounting the terminal
# mounting an absolute path on my computer directory to ubuntu home/data
# directory
docker run -v /Users/codecaine/Desktop:/home/data -it ubuntu

# run these two commands to be able to install packages with apt-get
apt-get -y update
apt-get -y curl

# installing python and nodejs with apt-get
apt-get -y python3.10 
apt-get -y install nodejs
Comment

python docker

docker pull python
Comment

PREVIOUS NEXT
Code Example
Shell :: ssh key 
Shell :: Creating a directory or folder in linux 
Shell :: create md5 hash command line 
Shell :: linux command to go to the previous directory 
Shell :: how to kill all emulator 
Shell :: docker get image size before pull acr 
Shell :: docker compose install centos 8 
Shell :: Permission denied (publickey,keyboard-interactive). 
Shell :: vijm jump to end of file 
Shell :: linux bash connect to postgres 
Shell :: android uninstall application adb 
Shell :: git force lf 
Shell :: ssh permission denied publickey 
Shell :: raspberry clear cache 
Shell :: git bash gradle weird characters 
Shell :: git commands list 
Shell :: linux hex to dec 
Shell :: debian ssh authorized_keys 
Shell :: merge master to dev branch 
Shell :: bash calculate sum 
Shell :: github pages is not free 
Shell :: uninstall git 
Shell :: git undo unstaged changes to one file 
Shell :: how to delete all pods in kubernetes 
Shell :: check number of cores in ubuntu 
Shell :: create new file in terminal 
Shell :: ffmpeg video size reduction 
Shell :: stop elasticsearch node 
Shell :: parquet tools install mac 
Shell :: how to open a folder using terminal 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =