Dockerfile for pyenv environment

  • Use a base image with a specific version of Ubuntu

FROM ubuntu:20.04

ENV TZ = Asia\Taipei

  • Set environment variables for non-interactive apt installation

ENV DEBIAN_FRONTEND=noninteractive

  • Install essential packages

RUN apt-get update && \
apt-get install -y \
build-essential \
libssl-dev \
zlib1g-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
wget \
curl \
llvm \
libncurses5-dev \
libncursesw5-dev \
xz-utils \
tk-dev \
libffi-dev \
liblzma-dev \
python3-venv \
sudo \
git \
tree \
vim \
&& rm -rf /var/lib/apt/lists/*

  • Switch to the /home directory

RUN useradd -m -s /bin/bash fluber && \
usermod -aG sudo fluber

  • Set a password for the ‘fluber’ user (change ‘password’ to your desired password)

RUN echo ‘fluber:123456’ | chpasswd

  • Switch to the ‘fluber’ user

USER fluber

  • Set the working directory to the home directory of the ‘fluber’ user

WORKDIR /home/fluber

  • Install pyenv

RUN git clone https://github.com/pyenv/pyenv.git ~/.pyenv

  • Add pyenv to the PATH

ENV PATH=”/home/fluber/.pyenv/bin:${PATH}”
RUN echo ‘export PYENV_ROOT=”/home/fluber/.pyenv”‘ >> ~/.bashrc
RUN echo ‘export PATH=”$PYENV_ROOT/bin:$PATH”‘ >> ~/.bashrc
RUN echo ‘eval “$(pyenv init –path)”‘ >> ~/.bashrc
RUN echo ‘eval “$(pyenv init -)”‘ >> ~/.bashrc

  • Install Python 3.8.12 and set it as the default version

RUN pyenv install 3.8.12 && \
pyenv global 3.8.12

  • Create a user named ‘fluber’ with sudo permissions
  • Expose any ports you need for your application (if applicable)
  • EXPOSE …
  • Start a bash shell when the container runs

CMD [“/bin/bash”]

分類: Django,標籤: , 。這篇內容的永久連結

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *