Skip to content

Instantly share code, notes, and snippets.

@jboelter
Created July 7, 2018 16:37
Show Gist options
  • Save jboelter/762b8333a0a2dfd9551e01d359f32315 to your computer and use it in GitHub Desktop.
Save jboelter/762b8333a0a2dfd9551e01d359f32315 to your computer and use it in GitHub Desktop.
Dockerfile w/ volume and correct permissions
# docker build . -t your:tag
# run the container and mount some directory into /data
# the startup script will create a user and launch CMD w/ the matching the UID:GID
# docker run --rm -it `pwd`:/data your:tag
FROM mhart/alpine-node
ENV GOSU_VERSION 1.10
RUN set -ex; \
\
apk add --no-cache --virtual .gosu-deps \
dpkg \
gnupg \
openssl \
; \
\
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \
\
# verify the signature
export GNUPGHOME="$(mktemp -d)"; \
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc; \
\
chmod +x /usr/local/bin/gosu; \
# verify that the binary works
gosu nobody true; \
\
apk del .gosu-deps
COPY startup.sh /
ENTRYPOINT ["/startup.sh"]
CMD "/bin/ash"
#!/bin/sh
#
set -e
# create a user using the permissions from the mounted volume at /data
# username: docker
# group: docker
addgroup -g `stat -c "%g" /data` docker
adduser -D -u `stat -c "%u" /data` -G docker -s /bin/ash docker
exec gosu docker "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment