Skip to content

Commit 830c1e0

Browse files
committed
Update Dockerfile and docker-compose.yml to enhance development environment
- Added additional packages including vim and openssh-client to Dockerfile - Improved Oh My Zsh installation with Powerlevel10k theme and plugins - Configured non-root user 'developer' with sudo privileges in Dockerfile - Updated docker-compose.yml to mount the correct working directory for the developer user
1 parent 04caef7 commit 830c1e0

File tree

2 files changed

+66
-11
lines changed

2 files changed

+66
-11
lines changed

Dockerfile

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ ENV DEBIAN_FRONTEND=noninteractive
88
# ---- Non‑interactive apt install -------------------------------------------
99
RUN apt-get update && \
1010
apt-get install -y --no-install-recommends \
11-
zsh git curl wget ca-certificates locales lsb-release dotnet-sdk-8.0 sudo && \
11+
zsh git curl wget ca-certificates locales lsb-release fontconfig dotnet-sdk-8.0 sudo vim \
12+
openssh-client && \
1213
locale-gen en_US.UTF-8 && \
1314
apt-get clean && rm -rf /var/lib/apt/lists/*
1415

@@ -32,25 +33,78 @@ RUN ARCH=$(dpkg --print-architecture) && \
3233
echo "Unsupported architecture: $ARCH" && exit 1; \
3334
fi
3435

36+
# ---- Verify & keep image slim ----------------------------------------------
37+
RUN zsh --version && pwsh -NoLogo -Command '$PSVersionTable'
38+
3539
# ---- Opinionated Oh My Zsh (unattended) ------------------------------------
36-
RUN wget -q https://github.com/deluan/zsh-in-docker/releases/download/v1.2.1/zsh-in-docker.sh -O /tmp/zsh-in-docker.sh && \
37-
sh /tmp/zsh-in-docker.sh -- -p git -p ssh-agent && \
40+
RUN sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" --unattended && \
41+
git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-/root/.oh-my-zsh/custom}/plugins/zsh-autosuggestions && \
42+
git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting ${ZSH_CUSTOM:-/root/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting && \
43+
git clone --depth=1 https://github.com/zdharma-continuum/fast-syntax-highlighting ${ZSH_CUSTOM:-/root/.oh-my-zsh/custom}/plugins/fast-syntax-highlighting && \
44+
git clone --depth=1 https://github.com/marlonrichert/zsh-autocomplete ${ZSH_CUSTOM:-/root/.oh-my-zsh/custom}/plugins/zsh-autocomplete && \
45+
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-/root/.oh-my-zsh/custom}/themes/powerlevel10k && \
46+
# Install Powerlevel10k MesloLGS NF fonts
47+
wget -O /tmp/MesloLGS_NF_Regular.ttf https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf && \
48+
wget -O /tmp/MesloLGS_NF_Bold.ttf https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf && \
49+
wget -O /tmp/MesloLGS_NF_Italic.ttf https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf && \
50+
wget -O /tmp/MesloLGS_NF_Bold_Italic.ttf https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf && \
51+
mkdir -p /usr/share/fonts/truetype/powerlevel10k && \
52+
mv /tmp/*.ttf /usr/share/fonts/truetype/powerlevel10k/ && \
53+
fc-cache -fv && \
3854
chsh -s /usr/bin/zsh root && \
39-
rm /tmp/zsh-in-docker.sh
55+
# configure default theme and plugins for root
56+
sed -i 's|^ZSH_THEME=.*|ZSH_THEME="powerlevel10k/powerlevel10k"|' /root/.zshrc && \
57+
sed -i 's|^plugins=.*|plugins=(git ssh-agent zsh-autosuggestions zsh-syntax-highlighting fast-syntax-highlighting zsh-autocomplete)|' /root/.zshrc && \
58+
echo '[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh' >> /root/.zshrc && \
59+
# Prepend Powerlevel10k instant prompt block to root .zshrc
60+
printf '%s\n' \
61+
'# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.' \
62+
'# Initialization code that may require console input (password prompts, [y/n]' \
63+
'# confirmations, etc.) must go above this block; everything else may go below.' \
64+
'if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then' \
65+
' source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"' \
66+
'fi' | cat - /root/.zshrc > /root/.zshrc.tmp && mv /root/.zshrc.tmp /root/.zshrc
67+
68+
RUN mkdir -p /root/.ssh && chmod 700 /root/.ssh && \
69+
echo 'export EDITOR=vim' >> /root/.zshrc && \
70+
echo 'export VISUAL=vim' >> /root/.zshrc && \
71+
echo 'export DEBIAN_FRONTEND=dialog' >> /root/.zshrc && \
72+
# Automatically cd into ~/source if it exists
73+
echo 'if [[ -d ~/source ]]; then' >> /root/.zshrc && \
74+
echo ' cd ~/source' >> /root/.zshrc && \
75+
echo 'fi' >> /root/.zshrc
4076

4177
# ---- PowerShell: ensure latest patch & install DSC v3 -----------------------
4278
RUN pwsh -NoLogo -NoProfile -Command \
4379
'Install-PSResource PSDSC -TrustRepository -Quiet; Install-DscExe -IncludePrerelease -Force'
4480

45-
# ---- Verify & keep image slim ----------------------------------------------
46-
RUN zsh --version && pwsh -NoLogo -Command '$PSVersionTable'
81+
# Switch back to dialog for any ad-hoc use of apt-get
82+
ENV DEBIAN_FRONTEND=dialog
83+
84+
# Add custom Powerlevel10k config
85+
COPY .pk10k.zsh /root/.p10k.zsh
86+
87+
# ---- Create non-root user 'developer' with sudo privileges ----
88+
RUN useradd -ms /usr/bin/zsh developer && \
89+
echo "developer ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/developer && \
90+
echo 'Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"' > /etc/sudoers.d/secure_path && \
91+
chmod 0440 /etc/sudoers.d/developer /etc/sudoers.d/secure_path
92+
93+
# ---- Copy root’s config to the user 'developer' ----
94+
RUN cp -R /root/.oh-my-zsh /home/developer/ && \
95+
cp /root/.zshrc /home/developer/.zshrc && \
96+
cp /root/.p10k.zsh /home/developer/.p10k.zsh && \
97+
touch /home/developer/.zprofile /home/developer/.zshenv /home/developer/.zlogin && \
98+
sed -i 's|^export ZSH=.*|export ZSH="$HOME/.oh-my-zsh"|' /home/developer/.zshrc && \
99+
chown -R developer:developer /home/developer && \
100+
mkdir -p /home/developer/.ssh && chmod 700 /home/developer/.ssh && chown developer:developer /home/developer/.ssh
101+
102+
USER developer
103+
WORKDIR /home/developer
47104

48105
# ---- Healthcheck -----------------------------------------------------------
49106
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 CMD pwsh -NoLogo -Command '$PSVersionTable | Out-Null || exit 1'
50107

51-
# Switch back to dialog for any ad-hoc use of apt-get
52-
ENV DEBIAN_FRONTEND=dialog
53-
54108
# ---- Default shell ----------------------------------------------------------
55109
CMD ["zsh"]
56110

docker-compose.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
services:
22
dev:
33
build: .
4+
user: developer
45
volumes:
5-
- .:/work
6-
working_dir: /work
6+
- .:/home/developer/work
7+
working_dir: /home/developer/work
78
entrypoint: zsh
89
stdin_open: true
910
tty: true

0 commit comments

Comments
 (0)