Web & iOS dev – Ruby, Rails, RubyMotion & React

Paul Sturgess

Setup Webpacker Webpack-dev-server With Docker-compose

The rails/webpacker gem is a fantastic way to configure webpack for your Rails application. However, it has gone through quite a few different configuration options to get it working with Docker.

Initially you could set the host by using command line arguments, but as of version 3.0.2 and this Pull Request the command line argument support was removed in favour of environment variables. By setting various environment variables you can override all dev server settings defined in config/webpacker.yml.

So now my docker-compose.yml config looks something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
web:
    <<: *app
    command: /src/docker/web.sh
    ports:
      - "3000:3000"
    depends_on:
      - webpack
    environment:
      - WEBPACKER_DEV_SERVER_HOST=webpack

  webpack:
    <<: *app
    command: ./bin/webpack-dev-server
    ports:
      - 3035:3035
    environment:
      - WEBPACKER_DEV_SERVER_HOST=0.0.0.0

To install yarn and nodejs I added the following to my Debian based dockerfile:

1
2
3
4
5
6
7
8
9
10
RUN apt-get update && apt-get install apt-transport-https

RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
  && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
  && curl -sL https://deb.nodesource.com/setup_8.x | bash -

RUN apt-get update && \
  apt-get install -y \
  yarn
  nodejs