Skip to content

Commit

Permalink
Update Dockerfile to support build an docker image.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanglu0704 committed Jun 27, 2023
1 parent 7c54fa4 commit b678383
Showing 1 changed file with 59 additions and 51 deletions.
110 changes: 59 additions & 51 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,53 +1,61 @@
#Change to your base image, such as pytorch1.11+py38
#https://docs.nvidia.com/deeplearning/frameworks/pytorch-release-notes/rel_21-02.html#rel_21-02
FROM nvcr.io/nvidia/pytorch:21.06-py3
#You can set available pypi sources
RUN /bin/bash -c "pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple"

ENV STAGE_DIR=/tmp
RUN mkdir -p ${STAGE_DIR}
#Ubuntu
RUN apt-get update && apt-get install -y openssh-server && apt-get install -y git
ARG SSH_PORT=6001
#Client Liveness & Uncomment Port 22 for SSH Daemon
RUN echo "ClientAliveInterval 30" >> /etc/ssh/sshd_config
RUN mkdir -p /var/run/sshd && cp /etc/ssh/sshd_config ${STAGE_DIR}/sshd_config && \
sed "0,/^#Port 22/s//Port 22/" ${STAGE_DIR}/sshd_config > /etc/ssh/sshd_config
RUN cat /etc/ssh/sshd_config > ${STAGE_DIR}/sshd_config && \
sed "0,/^Port 22/s//Port ${SSH_PORT}/" ${STAGE_DIR}/sshd_config > /etc/ssh/sshd_config && \
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
EXPOSE ${SSH_PORT}

#Set SSH KEY
RUN mkdir /root/.ssh
RUN printf "#StrictHostKeyChecking no\n#UserKnownHostsFile /dev/null" >> /etc/ssh/ssh_config && \
ssh-keygen -t rsa -f /root/.ssh/id_rsa -N "" && cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys && \
chmod og-wx /root/.ssh/authorized_keys

RUN echo $'Host 127.0.0.1 \n\
Hostname 127.0.0.1 \n\
Port 6001 \n\
StrictHostKeyChecking no \n\
User root' > /root/.ssh/config
RUN echo $'Host localhost \n\
Hostname localhost \n\
Port 6001 \n\
StrictHostKeyChecking no \n\
User root' >> /root/.ssh/config

RUN echo "service ssh start" >> /root/.bashrc

#Main deps
RUN pip install tensorboard
RUN pip install sentencepiece
RUN pip install boto3
RUN pip install jieba
RUN pip install ftfy
RUN pip install deepspeed==0.7.7
RUN pip install bmtrain

RUN pip install flagai
#For development usage, you can change as follows
#RUN git clone https://github.com/FlagAI-Open/FlagAI.git && cd FlagAI && python setup.py install
FROM nvcr.io/nvidia/cuda:11.7.0-devel-ubuntu20.04

LABEL zhanglu0704

ENV TZ=Asia/Shanghai

VOLUME /etc/localtime

ENV WORK_DID=/workspace

WORKDIR ${WORK_DID}

RUN apt update && \
apt install -y g++ gcc cmake curl wget vim unzip git openssh-server net-tools python3-packaging && \
apt install -y python3.9 python3.9-dev python3-pip && \
apt clean -y && \
rm -rf /var/cache/apt/archives

RUN rm /usr/bin/python3 && \
ln -s /usr/bin/python3.9 /usr/bin/python3 && \
ln -s /usr/bin/python3 /usr/bin/python && \
python -m pip install --upgrade pip

RUN pip install torch==1.13.0+cu117 torchvision==0.14.0+cu117 torchaudio==0.13.0 \
--extra-index-url https://download.pytorch.org/whl/cu117

COPY requirements.txt ${WORK_DID}/

RUN python -m pip install -r ${WORK_DID}/requirements.txt

RUN git clone https://github.com/NVIDIA/apex && \
cd apex && \
# git checkout -f 23.05 && \
# pip install -v --disable-pip-version-check --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" . && \
pip install -v --disable-pip-version-check --no-cache-dir --no-build-isolation --config-settings "--build-option=--cpp_ext" --config-settings "--build-option=--cuda_ext" . && \
cd ../ && rm -rf apex

RUN git clone https://github.com/OpenBMB/BMTrain && \
cd BMTrain && \
git checkout -f 0.2.2 && \
# python setup.py install --prefix=/usr/local/
pip install -v . && \
cd ../ && rm -rf BMTrain

RUN git clone https://github.com/FlagAI-Open/FlagAI.git && \
cd FlagAI && \
pip install -v . && \
cd ../ && rm -rf FlagAI

RUN echo "ClientAliveInterval 30" >> /etc/ssh/sshd_config && \
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config && \
echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config && \
echo "UserKnownHostsFile /dev/null" >> /etc/ssh/ssh_config

RUN ssh-keygen -t rsa -f /root/.ssh/id_rsa -N "" && \
cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys && \
chmod og-wx /root/.ssh/authorized_keys

CMD service ssh start && tail -f /dev/null

# sudo docker build -f Dockerfile --shm-size='120g' -t flagai:dev-ubuntu20-cuda11.7-py39 .

0 comments on commit b678383

Please sign in to comment.