Skip to content

Commit 9cbde5b

Browse files
authored
Add zshell support on docker. (#8)
1 parent c2deec5 commit 9cbde5b

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,20 @@ RUN rm requirements.txt requirements-dev.txt
6464
# Add PATH
6565
RUN echo "export PATH=/home/user/.local/bin:\$PATH" >> /home/user/.bashrc
6666
RUN echo "export LC_ALL=C.UTF-8 && export LANG=C.UTF-8" >> /home/user/.bashrc
67+
68+
# Install zsh with powerlevel10k theme
69+
ARG USE_ZSH=true
70+
71+
RUN sudo apt-get install -y zsh && \
72+
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended && \
73+
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
74+
COPY res/.zshrc res/.p10k.zsh /home/user/
75+
RUN sudo chown user:user .zshrc .p10k.zsh
76+
77+
RUN if [ "$USE_ZSH" = "true" ]; then \
78+
sudo chsh -s $(which zsh) $(whoami) && \
79+
echo "\n# Custom settings" >> /home/user/.zshrc && \
80+
echo "export PATH=/home/user/.local/bin:\$PATH" >> /home/user/.zshrc && \
81+
echo "export LC_ALL=C.UTF-8 && export LANG=C.UTF-8" >> /home/user/.zshrc; \
82+
fi
83+

run_docker.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,26 @@ DOCKER_TAG=$ORG/$PRJ_NAME
1717
CMD_ARGS=( ${@} )
1818
CMD_ARGS=${CMD_ARGS[*]:1}
1919

20+
RUN_SHELL=/usr/bin/zsh
21+
2022
if [[ $2 == :* ]]; then
2123
DOCKER_TAG=$DOCKER_TAG$2
2224
CMD_ARGS=${CMD_ARGS[*]:2}
25+
elif [ "$2" = "bash" ]; then
26+
RUN_SHELL=/bin/bash
27+
$RUN_SHELL CMD_ARGS=${CMD_ARGS[*]:2}
2328
fi
2429

2530
if [ "$1" = "build" ]; then
31+
if [ "$RUN_SHELL" = "/bin/bash" ]; then
32+
CMD_ARGS="$CMD_ARGS --build-arg USE_ZSH=false"
33+
fi
2634
echo "Building a docker image with tagname $DOCKER_TAG and arguments $CMD_ARGS"
2735
docker build . -t $DOCKER_TAG $CMD_ARGS --build-arg UID=`id -u` --build-arg GID=`id -g`
2836
elif [ "$1" = "run" ]; then
37+
if test -f "$HOME/.gitconfig"; then
38+
CMD_ARGS="$CMD_ARGS -v $HOME/.gitconfig:/home/user/.gitconfig"
39+
fi
2940
echo "Run a docker image with tagname $DOCKER_TAG and arguments $CMD_ARGS"
3041

3142
docker run -tid --privileged --gpus all \
@@ -36,18 +47,18 @@ elif [ "$1" = "run" ]; then
3647
-v $PWD:/home/user/$PRJ_NAME \
3748
--network host \
3849
$CMD_ARGS \
39-
$DOCKER_TAG /bin/bash
50+
$DOCKER_TAG $RUN_SHELL
4051

4152
last_cont_id=$(docker ps -qn 1)
4253
echo $(docker ps -qn 1) > $PWD/.last_exec_cont_id.txt
4354

44-
docker exec -ti $last_cont_id /bin/bash
55+
docker exec -ti $last_cont_id $RUN_SHELL
4556
elif [ "$1" = "exec" ]; then
4657
echo "Execute the last docker container"
4758

4859
last_cont_id=$(tail -1 $PWD/.last_exec_cont_id.txt)
4960
docker start ${last_cont_id}
50-
docker exec -ti ${last_cont_id} /bin/bash
61+
docker exec -ti ${last_cont_id} $RUN_SHELL
5162
else
5263
echo ""
5364
echo "============= $0 [Usages] ============"

0 commit comments

Comments
 (0)