本帖最后由 lyly125 于 2021-12-23 10:03 编辑
来吾爱好多年了,但是一直没有发过帖子,这是第一次发贴,如有错误的地方还请版主大大告知,立马改正!最近在学习和研究Docker,打算自定义一套自己的node相关镜像,采用的是Docker官方的 debian:bullseye 版本,安装NVM管理工具。由于环境问题,装Debian的官方源替换成清华源,用手动方式安装NVM:需要在Build之前先在Github下载想要安装的NVM版本源码,放在Dockerfile文件所在目录(必须!)
下面是我修改的Dockerfile代码,如果各位大大有疑问或者建议可以提出,本人还只是个菜鸟,希望和各位大大交流学习!
FROM debian:bullseye
################################Custom##########################################
# set timezone
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# install apt-transport-https ca-certificates
RUN apt-get update \
&& apt-get install -y apt-transport-https ca-certificates
# https://mirrors.tuna.tsinghua.edu.cn/help/debian/
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && \
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free" >> /etc/apt/sources.list && \
echo "# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free" >> /etc/apt/sources.list && \
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free" >> /etc/apt/sources.list && \
echo "# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free" >> /etc/apt/sources.list && \
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free" >> /etc/apt/sources.list && \
echo "# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free" >> /etc/apt/sources.list && \
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free" >> /etc/apt/sources.list && \
echo "# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free" >> /etc/apt/sources.list
# install the git and other app we need
RUN apt-get update \
&& apt-get install -y git vim wget \
&& rm -rf /var/lib/apt/lists/*
# nvm config for ~/.bashrc, ~/.profile, or ~/.zshrc file
RUN { \
echo 'export NVM_DIR="$HOME/.nvm"'; \
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm'; \
echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion'; \
} > /root/.bashrc
# copy nvm folder from host to container
COPY nvm/ root/.nvm/
# install node 12
RUN /bin/bash -c "source /root/.bashrc;nvm install 12"
# install lts, sass, sass-convert
# RUN /bin/bash -c "source /root/.bashrc"
# RUN /bin/bash -c "source /root/.bashrc;nvm install --lts"
# RUN /bin/bash -c "source /root/.bashrc;npm install -g sass"
# RUN /bin/bash -c "source /root/.bashrc;npm install apidoc -g"
# RUN /bin/bash -c "source /root/.bashrc;npm install -g sass-convert"
EXPOSE 80
EXPOSE 443
WORKDIR "/var/www/html"
Github地址
|