Last active
September 5, 2024 03:23
-
-
Save arctic-hen7/2281c59d369df0a472cb0d457f6c47c8 to your computer and use it in GitHub Desktop.
Starter Dockerfile with ZSH (NodeJS)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
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.
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
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.