Skip to content

Instantly share code, notes, and snippets.

Last active Apr 17, 2021
What would you like to do?
Starter Dockerfile with ZSH (Alpine)
# Setup Stage - set up the ZSH environment for optimal developer experience
FROM alpine:latest AS setup
# Let scripts know we're running in Docker (useful for containerised development)
# Use the unprivileged `main` user (created without a password ith `-D`) for safety
RUN adduser -D main
RUN mkdir -p /app \
&& chown -R main:main /app
# Set up ZSH and our preferred terminal environment for containers
RUN apk --no-cache add zsh curl git
RUN mkdir -p /home/main/.antigen
RUN curl -L > /home/main/.antigen/antigen.zsh
# Use my starter Docker ZSH config file for this, or your own ZSH configuration file (
COPY /home/main/.zshrc
RUN chown -R main:main /home/main/.antigen /home/main/.zshrc
# Set up ZSH as the unprivileged user (we just need to start it, it'll initialise our setup itself)
USER main
RUN /bin/zsh /home/main/.zshrc
# Switch back to root for whatever else we're doing
USER root
Copy link

arctic-hen7 commented Apr 15, 2021

If you're using NodeJS, use this instead, it uses the node user by default, and does everything else identically.

Copy link

arctic-hen7 commented Apr 15, 2021

This Dockerfile needs a ZSH configuration at You can either provide a copy of your own existing ZSH config, or you can use my starter config from here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment