Skip to content

Instantly share code, notes, and snippets.

@felipecabargas
Created July 27, 2018 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipecabargas/24f96c4b375055298d8c64969e077054 to your computer and use it in GitHub Desktop.
Save felipecabargas/24f96c4b375055298d8c64969e077054 to your computer and use it in GitHub Desktop.
Docker 101 Deck - Demo

Docker 101

--

  • Create a folder called demo
mkdir demo
  • Create a Gemfile with the following contents
ruby '2.4.4'
source 'https://rubygems.org'
  • Run:
touch Gemfile.lock
  • Create a Dockerfile with the following contents
FROM ruby:2.4
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /demo
WORKDIR /demo
COPY Gemfile /demo/Gemfile
COPY Gemfile.lock /demo/Gemfile.lock
RUN bundle install
COPY . /demo
  • Create a docker-compose.yml with the following contents
version: '3'
services:
  db:
    image: postgres
    volumes:
      - ./tmp/db:/var/lib/postgresql/data
  web:
    build: .
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    volumes:
      - .:/demo
    ports:
      - "3000:3000"
    depends_on:
      - db
  • Run
docker-compose run web rails new . --force --database=postgresql
  • Edit the config/database.yml file and replace the default section with:
default: &default
  adapter: postgresql
  encoding: unicode
  user: postgres
  password:
  host: db
  • Run
docker-compose run web rake db:create
docker-compose up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment