Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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

docker python

# 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

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

dockerfile to run python script

docker run -it --rm --name my-first-python-script -v "$PWD":/usr/src/widget_app python:3 python my_script.py
Comment

Docker Python Script Run

# Dockerfile
FROM python:3

ADD my_script.py /

CMD [ "python", "./my_script.py" ]

# Commandline
docker run IMAGE /path/to/script.py
Comment

docker run python

docker run -it --rm --name python-script -v "$PWD":/usr/src/app python:3 python ./usr/src/app/script.py
Comment

python docker

docker pull python
Comment

PREVIOUS NEXT
Code Example
Python :: toolbar pyqt 
Python :: numpy if zero is present 
Python :: read file from drive in colab 
Python :: flask blueprints 
Python :: pandas print column by index 
Python :: django serializer get image list 
Python :: read csv pandas nrow 
Python :: setup mongodb database with django 
Python :: defaultdict in python 
Python :: rolling std dev of a pandas series 
Python :: compare dates in python 
Python :: quadratic equation python 
Python :: python csv find specific string 
Python :: Working with WTForms FieldList 
Python :: onehotencoder = OneHotEncoder(categorical_features = [1]) X = onehotencoder.fit_transform(X).toarray() X = X[:, 1:] 
Python :: qtimer singleshot 
Python :: merge two arrays python 
Python :: override get_queryset django with url parameters 
Python :: pyhton apend to list 
Python :: python colored text in console 
Python :: geopandas read postgis SQL 
Python :: tuple push 
Python :: name columns pandas 
Python :: python re split 
Python :: open file in python 
Python :: run a for loop in python 
Python :: np array size 
Python :: jupyter notebook bold text 
Python :: How to Get the Symmetric Difference of Sets in Python 
Python :: update django model with dict 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =