Created
July 7, 2018 16:37
-
-
Save jboelter/762b8333a0a2dfd9551e01d359f32315 to your computer and use it in GitHub Desktop.
Dockerfile w/ volume and correct permissions
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
# 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" | |
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
#!/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