Skip to content

Instantly share code, notes, and snippets.

@pdonorio
Last active May 13, 2022 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pdonorio/82df22b0bdce4676981a0c482695a301 to your computer and use it in GitHub Desktop.
Save pdonorio/82df22b0bdce4676981a0c482695a301 to your computer and use it in GitHub Desktop.
A template for best practices in writing a docker image
#!/bin/bash
set -e
if [ "$1" == 'mycmd' ]; then
echo "I do what is usual"
# INIT?
# EXECUTE CUSTOM SCRIPTS?
for f in /docker-entrypoint.d/*; do
case "$f" in
*.sh) echo "$0: running $f"; . "$f" ;;
*) echo "$0: ignoring $f" ;;
esac
echo
done
else
echo "Executed requested command?"
$1
fi
#######################
## BUILD BASE
# Small image
FROM alpine:3.5
# or
FROM ubuntu:16.04
# LTS
MAINTAINER "myself"
# allow custom scripts to be executed at launch time
RUN mkdir /docker-entrypoint.d/
#######################
## ENVIRONMENT VARIABLES with VERSIONS or SETUP
ENV MYSOFTWV 1.0
# Set utf8
ENV LANG en_US.utf8
#######################
## INSTALL PACKAGE FROM PACKAGING SYSTEM
RUN apt/apk update && install && clean
#######################
## SUBPACKAGING and CONFIGURING
RUN pip install ...
RUN dpkg ...
#######################
## VOLUMES
VOLUME /var/lib/mysoftware
#######################
## ENTRYPOINT
COPY docker-entrypoint.sh /usr/local/bin/
# RUN ln -s usr/local/bin/docker-entrypoint.sh / # backwards compat
ENTRYPOINT ["docker-entrypoint.sh"]
#######################
## EXPOSE ports and launch command
EXPOSE 5432
CMD ["mycmd"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment