- Pull the image.
docker pull python:3.8.0-alpine3.10
# python:3.8-slim-buster
# python:3.8
docker image ls
- Run image.
docker container run --rm -it python:3.8.0-alpine3.10
# --rm remove after exit
# -it enter after create
docker container run --rm -it python:3.8.0-alpine3.10 python -V
docker container run --rm -it python:3.8.0-alpine3.10 pip -V
docker container run --rm -it python:3.8.0-alpine3.10 cat /etc/os-release
# the ending is cmd in image
- Create script.
main.py
import os
- Run script that has no dependency.
docker container run --rm -it
-v /path/to/folder:/workfolder:ro # read only
python:3.8.0-alpine3.10
python /workfolder/main.py
- Need Dockerfile for build.
FROM python:3.8
RUN pip3 install -r requirements.txt
# RUN apt-get -y update (optional)
RUN mkdir -p /workfolder
COPY ./main.py /workfolder/
CMD [ "python" , "/workfolder/main.py" ] # similar to subprocess
- Run image build based on Dockerfile.
docker image build -t goodpython:v01 .
docker image ls
docker container run --rm -it goodpython:v01 # repo:tag