Skip to content

Instantly share code, notes, and snippets.

@karthiks
Created April 16, 2026 16:39
Show Gist options
  • Select an option

  • Save karthiks/4bf09a2a19d6122f587b68bfb7ddeb4e to your computer and use it in GitHub Desktop.

Select an option

Save karthiks/4bf09a2a19d6122f587b68bfb7ddeb4e to your computer and use it in GitHub Desktop.
Replace bash with zsh in Docker Container
# Objective: Replace bash with zsh in Docker Container
# Build:
# docker build -f Dockerfile.zsh -t zsh-ed .
# Run n Verify:
# docker run -it --rm zsh-ed whoami
FROM node:20-bookworm-slim
# node is built-in user that comes with the image - node:20-bookworm-slim.
ARG USERNAME=node
# ============================================
# Step 1: Install System Dependencies
# ============================================
RUN apt-get update && apt-get install -y --no-install-recommends \
zsh \
wget curl git vim jq ca-certificates \
sudo \
&& rm -rf /var/lib/apt/lists/*
# ============================================
# Step 2: Set zsh as the system default for the non-root user (adjust user name as needed)
# ============================================
RUN chsh -s $(which zsh) $USERNAME
# ============================================
# Step 3: Setup Workspace
# ============================================
USER $USERNAME
WORKDIR /workspace
RUN chown $USERNAME:$USERNAME /workspace
# ============================================
# Step 4: Create a small bashrc that hands interactive bash sessions over to zsh
# This one is fall-back when Step-2 above, fails to change shell prompt to zsh. This sure works!
# ============================================
RUN echo 'if [ -t 1 ]; then\n exec /bin/zsh\nfi' > /home/$USERNAME/.bashrc
# ENTRYPOINT [ "bash"]
# ENTRYPOINT [ "/bin/bash", "-i"]
ENTRYPOINT [ "/bin/zsh" ]
CMD ["-l"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment