先贴出我的 Dockerfile
FROM python:3.10-buster
RUN (echo "deb http://mirrors.aliyun.com/debian/ buster main non-free contrib" > /etc/apt/sources.list) && (apt-get update) && (apt-get install -y vim netcat telnet)
RUN /usr/local/bin/python -m pip install --upgrade pip -i https://mirrors.aliyun.com/pypi/simple
RUN mkdir /code
WORKDIR /code
COPY requirements-prd.txt /code/
RUN pip install -i https://mirrors.aliyun.com/pypi/simple -r requirements-prd.txt
COPY config.yaml /code/
ADD . /code/
RUN groupadd -r ponponon && useradd -r -g ponponon ponponon
USER ponponon
关键在于最初两行
先来看看倒数第二行:
groupadd -r ponponon
创立用户组 ponpononuseradd -r -g ponponon ponponon
创立用户 ponponon,并增加到 ponponon 组中
最初一行就是指定 CMD 由那个用户运行