Simple sites with Middleman and Docker Multistage Builds
We still use middleman for our static sites. Below you’ll find a super simple docker file with multistage builds.
Here is our Dockerfile
. As you can see it builds it using 2 stages. One to build the container that runs middleman and one for copying the result in a small NGINX container.
# setup our builder
FROM ruby:2.3-alpine AS middleman-builder
WORKDIR /app
ENV RAILS_ENV production
RUN apk update && apk --update add ruby ruby-irb nodejs ruby-json ruby-rake \
ruby-bigdecimal ruby-io-console libstdc++ tzdata \
libffi-dev libxml2-dev libxslt-dev
# Necessary for some gems which are compiled on bundle install
RUN apk add --virtual build-deps git build-base ruby-dev \
libc-dev linux-headers && \
gem install bundler --no-ri --no-rdoc && \
bundle config build.nokogiri --use-system-libraries
# Only do a bundle install if the gemfile changes
COPY Gemfile* /app/
RUN bundle install --clean --without development test
COPY . /app
RUN bundle exec middleman build --verbose
# Copy the resulting code to the nginx container
FROM nginx:alpine
COPY --from=middleman-builder /app/build /usr/share/nginx/html
And then build it
docker build -t site .
And to run it
docker run -p 9090:80 site
You can open it on:
open http://localhost:9090
Tada! You now have a tiny site :)
Want to learn about multistage builds?
Have fun hacking!