Skip to content

Instantly share code, notes, and snippets.

@arctic-hen7
Last active February 4, 2024 20:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arctic-hen7/2281c59d369df0a472cb0d457f6c47c8 to your computer and use it in GitHub Desktop.
Save arctic-hen7/2281c59d369df0a472cb0d457f6c47c8 to your computer and use it in GitHub Desktop.
Starter Dockerfile with ZSH (NodeJS)
# Setup Stage - set up the ZSH environment for optimal developer experience
FROM node:14-alpine AS setup
# Let scripts know we're running in Docker (useful for containerised development)
ENV RUNNING_IN_DOCKER true
# Use the unprivileged `node` user (pre-created by the Node image) for safety (and because it has permission to install modules)
RUN mkdir -p /app \
&& chown -R node:node /app
# Set up ZSH and our preferred terminal environment for containers
RUN apk --no-cache add zsh curl git
RUN mkdir -p /home/node/.antigen
RUN curl -L git.io/antigen > /home/node/.antigen/antigen.zsh
# Use my starter Docker ZSH config file for this, or your own ZSH configuration file (https://gist.github.com/arctic-hen7/bbfcc3021f7592d2013ee70470fee60b)
COPY .dockershell.sh /home/node/.zshrc
RUN chown -R node:node /home/node/.antigen /home/node/.zshrc
# Set up ZSH as the unprivileged user (we just need to start it, it'll initialise our setup itself)
USER node
RUN /bin/zsh /home/node/.zshrc
# Switch back to root for whatever else we're doing
USER root
@arctic-hen7
Copy link
Author

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

@arctic-hen7
Copy link
Author

If you're not using NodeJS, use this instead, it uses pure Alpine and creates a non-root user itself, and does everything else identically.

@sahibjotsaggu
Copy link

For me, I had to add RUN adduser -D node above line 6.

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