Intro to Docker on Windows

Episode #72 by Teacher's Avatar David Kimura

Summary

Developing a Ruby on Rails application on Windows can be difficult, but doesn't have to be with Docker. Learn how to use Docker to create isolated containers and get them to talk with the Rails app and passed through to the local computer.
rails development deployment 11:19

Resources

Summary

# Terminal
docker build . -t railsapp
docker-compose up
docker-compose start web
docker-compose stop web

# Dockerfile
FROM ruby:2.3.3
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs 
RUN apt-get install libmysqlclient-dev -y
RUN apt-get install sqlite3 -y
RUN apt-get install coffeescript gawk g++ gcc make libreadline6-dev -y
RUN apt-get install libssl-dev libyaml-dev libsqlite3-dev autoconf libgmp-dev libgdbm-dev -y
RUN apt-get install libncurses5-dev automake libtool bison pkg-config libffi-dev -y
RUN mkdir /railsapp
RUN echo 'gem: --no-document' >> ~/.gemrc
EXPOSE 3000
WORKDIR /railsapp
ADD Gemfile /railsapp/Gemfile
ADD Gemfile.lock /railsapp/Gemfile.lock
RUN bundle install
ADD . /railsapp

# docker-compose.yml
version: '2'

services:
  web:
    build: .
    command: bash -c "bundle && bundle exec rake db:create db:migrate db:seed && bundle exec rails s -b 0.0.0.0"
    volumes:
      - .:/railsapp
    ports:
      - 3000:3000
    depends_on:
      - redis
      - mysql
  redis:
    image: redis
    ports:
      - 6379:6379
  mysql:
    image: mysql:5.7
    command: mysqld --character-set-server=utf8
    ports:
      - 3306:3306
    restart: always
    volumes: 
      - ../docker/mysql:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: development
      MYSQL_DATABASE: template_development
      MYSQL_USER: dbuser
      MYSQL_PASSWORD: password
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    ports:
      - 8080:80
    depends_on:
      - mysql
    environment:
      PMA_HOST: mysql
      PMA_PORT: 3306
      PMA_USER: dbuser
      PMA_PASSWORD: password