diff --git a/Dockerfile b/Dockerfile index a989578..dbbf47b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,10 +7,8 @@ LABEL Description="This image is used to learn building dockerfiles" \ # environment variables ENV JEKYLL_SITE=default - -# copy stuff into the image -COPY jekyll.sh jekyll.sh -RUN chmod +x jekyll.sh +ENV USER_ID=1000 +ENV GROUP_ID=1000 # expose port for `jekyll serve` EXPOSE 4000 @@ -18,9 +16,17 @@ EXPOSE 4000 # volume definitions VOLUME ["/mnt"] -# prepare the baseimage +# prepare the baseimage and create RUN apt-get update && apt-get install -y ruby ruby-dev gcc g++ make libssl-dev libreadline-dev && \ - gem update && gem install jekyll bundler + gem update && gem install jekyll bundler && \ + groupadd -g $GROUP_ID jekyll-dev && \ + useradd -u $USER_ID -g $GROUP_ID -M -d /mnt -s /bin/false jekyll-dev + +USER jekyll-dev + +RUN cd /mnt && \ + if [ ! -d "/mnt/$JEKYLL_SITE" ]; then jekyll new $JEKYLL_SITE; fi && \ + cd $JEKYLL_SITE && bundle install # run command -CMD ./jekyll.sh \ No newline at end of file +CMD bundle exec jekyll serve --host=0.0.0.0 --incremental \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 5f0237d..53f822f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,4 +10,6 @@ services: ports: - 127.0.0.1:4000:4000 environment: - - JEKYLL_SITE=docs \ No newline at end of file + - JEKYLL_SITE=docs + - USER_ID=1000 + - GROUP_ID=1000 \ No newline at end of file diff --git a/jekyll.sh b/jekyll.sh deleted file mode 100644 index 54086ff..0000000 --- a/jekyll.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -# create new or serve existing jekyll page (/mnt/$JEKYLL_SITE) - -cd /mnt -if [ ! -d "/mnt/$JEKYLL_SITE" ]; then - jekyll new $JEKYLL_SITE -fi -cd $JEKYLL_SITE -bundle install -bundle exec jekyll serve --host=0.0.0.0 --incremental \ No newline at end of file