Skip to content

Ubuntu20.04 Python3.9

Dockerfile

Dockerfile
FROM ubuntu:20.04

RUN apt update

RUN DEBIAN_FRONTEND=noninteractive TZ=Asia/Shanghai apt-get -y install tzdata
ENV TZ=Asia/Shanghai

RUN apt install -y make

RUN apt install -y python3.9 python3.9-dev python3-pip
RUN ln -s /usr/bin/python3.9 /usr/bin/python

# poetry
RUN python -m pip install poetry -i https://pypi.tuna.tsinghua.edu.cn/simple

# pdm
RUN pip install pdm

# postgres
RUN apt install -y libpq-dev
Dockerfile
FROM ubuntu:20.04

RUN apt update

RUN DEBIAN_FRONTEND=noninteractive TZ=Asia/Shanghai apt-get -y install tzdata
ENV TZ=Asia/Shanghai

RUN apt install -y python3.9 python3.9-dev python3-pip
RUN ln -s /usr/bin/python3.9 /usr/bin/python
RUN python -m pip install poetry

RUN apt install -y make

# Install curl and other dependencies required for later steps
RUN apt-get install -y \
    curl \
    wget \
    unzip \
    libglib2.0-0 \
    libnss3 \
    libgconf-2-4 \
    libfontconfig1 \
    fonts-wqy-zenhei

# Add Google Chrome repository and install Chromium
RUN curl -LO https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \
    apt-get install -y ./google-chrome-stable_current_amd64.deb && \
    rm google-chrome-stable_current_amd64.deb && \
    apt-get clean

# Set up Chrome WebDriver
# https://googlechromelabs.github.io/chrome-for-testing/
ARG CHROMEDRIVER_VERSION=126.0.6478.126
RUN wget -q https://storage.googleapis.com/chrome-for-testing-public/${CHROMEDRIVER_VERSION}/linux64/chromedriver-linux64.zip -O /tmp/chromedriver.zip
RUN unzip /tmp/chromedriver.zip -d /usr/local/bin/
RUN ls -al /usr/local/bin/
RUN rm /tmp/chromedriver.zip && chmod +x /usr/local/bin/chromedriver-linux64/chromedriver
Dockerfile
FROM ubuntu:20.04

RUN sed -i 's/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list
# RUN sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list

RUN apt update

RUN DEBIAN_FRONTEND=noninteractive TZ=Asia/Shanghai apt-get -y install tzdata
ENV TZ=Asia/Shanghai

RUN apt install -y python3.9 python3.9-dev python3-pip
RUN ln -s /usr/bin/python3.9 /usr/bin/python
RUN python -m pip install poetry -i https://pypi.tuna.tsinghua.edu.cn/simple

RUN apt install -y make

# 安装 .NET SDK
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        ca-certificates \
        curl \
        software-properties-common

RUN curl -sSL https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN add-apt-repository "$(curl -sSL https://packages.microsoft.com/config/ubuntu/20.04/prod.list)"

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        dotnet-sdk-6.0

ENV PYTHONNET_RUNTIME=dotnet
Makefile
IMAGE_TAG := u20p39
WORK_DIR  := /root/project
CACHE_DIR := /root/.cache
OUT_WORK_DIR := $(PWD)/project
OUT_CACHE_DIR := $(PWD)/__env_cache__

BIN_DOCKER := docker
BIN_DOCKER_COMPOSE := $(BIN_DOCKER)-compose

DOCKER_RUN := $(BIN_DOCKER) run \
--rm -it \
-v $(OUT_WORK_DIR):$(WORK_DIR) \
-v $(OUT_CACHE_DIR):$(CACHE_DIR) \
-w $(WORK_DIR) \
--net=host \
$(IMAGE_TAG)

build:
	@$(BIN_DOCKER) build . -t $(IMAGE_TAG)
up:
	@$(BIN_DOCKER_COMPOSE) up -d && $(BIN_DOCKER_COMPOSE) logs -f
down:
	@$(BIN_DOCKER_COMPOSE) down
logs:
	@$(BIN_DOCKER_COMPOSE) logs -f
bash:
	@$(DOCKER_RUN) /bin/bash
version:
	@$(DOCKER_RUN) poetry run python -V
init:
	@$(DOCKER_RUN) poetry init
install:
	@$(DOCKER_RUN) poetry install --no-root
add:
	@$(DOCKER_RUN) poetry add $(name)
remove:
	@$(DOCKER_RUN) poetry remove $(name)
run:
	@$(DOCKER_RUN) poetry run python $(name)
tests_env:
	@$(DOCKER_RUN) poetry add --group dev pytest pytest-asyncio
tests:
	@$(DOCKER_RUN) poetry run pytest tests.py
Makefile
IMAGE_TAG := u20p39
WORK_DIR  := /root/project
CACHE_DIR := /root/.cache
OUT_WORK_DIR := $(PWD)/project
OUT_CACHE_DIR := $(PWD)/__env_cache__

BIN_DOCKER := docker
BIN_DOCKER_COMPOSE := $(BIN_DOCKER)-compose

DOCKER_RUN := $(BIN_DOCKER) run \
--rm -it \
-v $(OUT_WORK_DIR):$(WORK_DIR) \
-v $(OUT_CACHE_DIR):$(CACHE_DIR) \
-w $(WORK_DIR) \
--net=host \
$(IMAGE_TAG)

build:
	@$(BIN_DOCKER) build . -t $(IMAGE_TAG)
up:
	@$(BIN_DOCKER_COMPOSE) up -d && $(BIN_DOCKER_COMPOSE) logs -f
down:
	@$(BIN_DOCKER_COMPOSE) down
logs:
	@$(BIN_DOCKER_COMPOSE) logs -f
bash:
	@$(DOCKER_RUN) /bin/bash
version:
	@$(DOCKER_RUN) pdm run python -V
init:
	@$(DOCKER_RUN) pdm init
install:
	@$(DOCKER_RUN) pdm install --no-self
add:
	@$(DOCKER_RUN) pdm add $(name)
run:
	@$(DOCKER_RUN) pdm run python $(name)
remove:
	@$(DOCKER_RUN) pdm remove $(name)
shell
make version
# Python 3.9.5

Released under the MIT License.