Skip to content

Instantly share code, notes, and snippets.

@eemi
Last active July 11, 2021 07:35
Show Gist options
  • Save eemi/61617a360b55476cc5150b1853303798 to your computer and use it in GitHub Desktop.
Save eemi/61617a360b55476cc5150b1853303798 to your computer and use it in GitHub Desktop.
Run a Middleman site with Docker compose

Based on https://docs.docker.com/compose/rails/

Dockerfile

FROM ruby:2.5.1
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /site
WORKDIR /site
ADD Gemfile /site/Gemfile
ADD Gemfile.lock /site/Gemfile.lock
RUN bundle install
ADD . /site

That’ll put your application code inside an image that will build a container with Ruby, Bundler and all your dependencies inside it. For more information on how to write Dockerfiles, see the Docker user guide and the Dockerfile reference.

Gemfile

source 'https://rubygems.org'
gem 'middleman'

You’ll need an empty Gemfile.lock in order to build our Dockerfile.

touch Gemfile.lock

docker-compose

Finally, docker-compose.yml is where the magic happens. This file describes the services that comprise your app, and the configuration needed to expose the web app’s port.

version: '2'
services:
  web:
    build: .
    command: bundle exec middleman --bind-address 0.0.0.0
    volumes:
      - .:/site
    ports:
      - "4567:4567"

Init middleman

With those three files in place, you can now generate your middleman site using docker-compose run:

docker-compose run web middleman init

Build the site

In order to build the site, you need to run:

docker-compose run web middleman build
@deepflame
Copy link

thanks for the writeup!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment